不能为每个人工作

时间:2013-10-15 20:41:20

标签: c++

#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;

错误:预期“(”之后。在每行上发生错误

我不认为我错过任何包含,这很奇怪。即时通讯xcode 4.3

2 个答案:

答案 0 :(得分:6)

语法错误。试试这个:

for(string s : vstr)
    cout<<s<<endl;

顺便说一句,不是初始化数组,而是复制到vector中,你可以一步完成,并且可以创建数组:

std::vector<std::string> sve{ "one","two", "three", "four", "five" };

答案 1 :(得分:0)

是无效的C ++ - 不编译是赠品

或许看看http://www.cplusplus.com/reference/algorithm/for_each/是你在想什么