【发布时间】:2012-07-07 13:53:37
【问题描述】:
我一直在尝试用双换行符 ("\n\n") 分割字符串。
input_string = "firstline\nsecondline\n\nthirdline\nfourthline";
size_t current;
size_t next = std::string::npos;
do {
current = next + 1;
next = input_string.find_first_of("\n\n", current);
cout << "[" << input_string.substr(current, next - current) << "]" << endl;
} while (next != std::string::npos);
给我输出
[firstline]
[secondline]
[]
[thirdline]
[fourthline]
这显然不是我想要的。我需要得到类似的东西
[first line
second line]
[third line
fourthline]
我也尝试过boost::split,但它给了我相同的结果。我错过了什么?
【问题讨论】: