(1)第一种,类似于数组的方式:
[cpp] view plain copy print?
- std::vector<std::string> strArray(10);
- strArray[0] = "hello";
- strArray[1] = "world";
- strArray[2] = "this";
- strArray[3] = "find";
- strArray[4] = "gank";
- strArray[5] = "pink";
- strArray[6 ]= "that";
- strArray[7] = "when";
- strArray[8] = "how";
- strArray[9] = "cpp";
(2)push_back的方式:
[cpp] view plain copy print?
- vector<string> strArray;
- strArray.push_back("hello");
- strArray.push_back("world");
- strArray.push_back("this");
- strArray.push_back("find");
- strArray.push_back("gank");
- strArray.push_back("pink");
- strArray.push_back("that");
- strArray.push_back("when");
- strArray.push_back("how");
- strArray.push_back("cpp");
(3)构造函数的方式:
[cpp] view plain copy print?
- string str[]={"hello","world","this","find","gank","pink","that","when","how","cpp"};
- vector<string> strArray(str, str+10);