給定一個包含字符串「Hello World」的文件(注意'Hello'和'World'之間有空格)。如何僅通過' n'在istream中分隔字符串?
int main()
{
ofstream fout("test.txt");
fout.write("Hello World", 12);
fout.close();
ifstream fin("test.txt");
vector<string> coll((istream_iterator<string>(fin)),
(istream_iterator<string>()));
// coll contains two strings 'Hello' and 'World' rather than
// one string "Hello World" that is just I want.
}
換句話說,我想在一個IStream字符串應該只有「\ n」,而不是「」,「\ n」分隔等
我應該怎麼辦?
我修改了原來的帖子。請查閱。 – xmllmx