This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
声明定义: | |
#include <map> | |
std::map<数据类型1,数据类型2> name | |
key value | |
for example: | |
std::map <std::string,int > mapstring; | |
std::map <std::string,char> mapstring; | |
添加数据: | |
map <int,string> maplive; | |
maplive.insert(pair<int,string>(321,"aclive")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
vector<数据类型> name; | |
example: | |
vector<int> vec; | |
尾部插入数字:vec.push_back(int a); | |
使用下标访问元素 std::cout<<vec[0]<<std::endl; 下标从0开始 | |
使用迭代器访问元素 | |
vector <int> ::iterator it; | |
for(it=vec.begin();it!=vec.end();++it) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
定义初始化: | |
#include<string> | |
string s1; //默认构造函数,s1为空串 | |
string s2(s1);将s2初始化为s1的一个副本 | |
string s3("value"); 将s3初始化一个字符串的值副本 | |
string s3(n,'c');将s4初始化为字符'c'的n个副本 | |
cin>>s5;读取有效字符直到遇到空格 'q' | |
getline(cin,s6); 读取字符到遇到换行,空格可读入,直到'\n'结束 ,'\n'被截取掉 | |
getline(cin,s7,'a'); 一个直到'a'结束,其中任何字符包括'\n'都能够读入 '\a'被截取掉 | |
输出: std::cout<<s1<<s2<<s3<<s4<<s5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
基于TCP的socket编程分为客户端和服务端 | |
客户端流程: | |
1.创建套接字(socket) | |
2.向服务器发出连接请求(connect) | |
3.和服务器端进行通信(send/receive) | |
4.关闭套接字 | |
服务端流程: | |
1.创建套接字(socket) | |
2.将套接字绑定到一个本地地址和端口上(bind) | |
3.将套接字设为监听模式,准备接收客户端请求(listen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json = { | |
"age":24, | |
"name":"cst" | |
}; | |
//修改json中的age值,因为json中存在age属性 | |
json["age"] = 30; | |
//增加json中的sex属性,因为json中不存在sex属性 | |
json["sex"] = "M"; | |
//遍历json中的数据 | |
for(var key in json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "rapidjson/document.h" | |
using namespace rapidjson; | |
Document document; | |
const char* json = { | |
"hello": "world", | |
"t": true , | |
"f": false, | |
"n": null, | |
"i": 123, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "rapidjson/rapidjson.h" | |
#include "rapidjson/prettywriter.h" | |
#include "rapidjson/document.h" | |
#include "rapidjson/stringbuffer.h" | |
using namespace rapidjson; | |
rapidjson::Document document; | |
document.SetObject(); | |
rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new Array(); | |
arr[0] = {"name":"LincolnBurrows","age":"26","sex":"male"}; | |
arr[1] = {"name":"yangdong","age":"20","sex":"male"}; | |
arr[2] = {"name":"jingjing","age":"19","sex":"female"}; | |
arr.push({"name":"kkkk","age":"2222"}); //数组push方法,相反pop方法 | |
arr.pop({"name":"kkkk","age":"2222"}); | |
for(var i = 0;i < arr.length;i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json_in_json = {}; | |
var user1 = {"_id":"1","name":"LincolnBurrows","age":"26","sex":"male"}; | |
var user2 = {"_id":"2","name":"yangdong","age":"20","sex":"male"}; | |
var user3 = {"_id":"3","name":"jingjing","age":"19","sex":"female"}; | |
json_in_json[user1._id] = user1; | |
json_in_json[user2._id] = user2; | |
json_in_json[user3._id] = user3; | |
console.log(json_in_json); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var schema = mongoose.Schema; | |
var doc_schema = new schema({array:Array}); | |
var doc = mongoose.model('doc',doc_schema); | |
var doc_inst = new doc({array:[1,2,3,4,5]}); | |
doc_inst.array.pull(3); //delete doc_inst array element '3' | |
console.log(doc_inst.array); |
OlderNewer