【发布时间】:2013-03-18 19:03:30
【问题描述】:
我正在接受 20 行输入。我想用空格分隔每一行的内容并将其放入向量向量中。如何制作向量的向量?我很难把它推回去......
我的输入文件:
Mary had a little lamb
lalala up the hill
the sun is up
矢量应该看起来像这样。
ROW 0: {"Mary","had", "a","little","lamb"}
ROW 1: {"lalala","up","the","hill"}
这是我的代码....
string line;
vector <vector<string> > big;
string buf;
for (int i = 0; i < 20; i++){
getline(cin, line);
stringstream ss(line);
while (ss >> buf){
(big[i]).push_back(buf);
}
}
【问题讨论】:
-
你那里有一个向量向量。你的代码有什么问题?
-
@AndyProwl 越界访问(假设代码是真实代码的良好表示)。
-
@juanchopanza:哦,对了 :) 好收获
-
+vote for mary had a little lamb而不是foo/bar