#include <iostream>
using namespace std;
#include <string>
// Sequence containers
#include <list>
#include <vector>
int main() {
string sve[MAX] = { "one","two", "three", "four", "five" };
//2
vector <string> vstr;
//3
for(int i=0;i<MAX;i++)
vstr.push_back(sve[i]);
//4
cout<<"---Vector---\n";
for each (string s in vstr)
cout<<s<<endl;
Run Code Online (Sandbox Code Playgroud)
错误:预期"("之后for.错误发生在每一行
我不认为我错过了任何包含,这很奇怪.即时通讯xcode 4.3
语法错误.试试这个 :
for(string s : vstr)
cout<<s<<endl;
Run Code Online (Sandbox Code Playgroud)
顺便说一下,不是初始化数组,而是复制到vector中,你可以一步完成,并且可以创建数组:
std::vector<std::string> sve{ "one","two", "three", "four", "five" };
Run Code Online (Sandbox Code Playgroud)