【发布时间】:2013-02-07 05:41:24
【问题描述】:
给定一个包含字符串“Hello World”的文件(注意“Hello”和“World”之间有一个空格)。
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' 等分隔。
我该怎么办?
【问题讨论】:
标签: c++ string stream iostream separator