我一直试图通过双换行符("\n\n"
)拆分字符串。C++通过双换行符拆分字符串
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
但它给了我同样的结果。我错过了什么?
inc在8分钟内接受答案。非常感谢你 – none 2012-07-07 08:32:36