【发布时间】:2014-01-04 02:48:07
【问题描述】:
给定一个字符串,例如“John Doe , USA , Male”,我将如何用逗号作为分隔符分割字符串。目前我使用 boost 库,我设法拆分,但空白会导致问题。
例如,上面的字符串一旦被分割成一个向量,就只包含“John”而不包含其余部分。
更新
这是我目前正在使用的代码
displayMsg(line);
displayMsg(std::string("Enter your details like so David Smith , USA, Male OR q to cancel"));
displayMsg(line);
std::cin >> res;
std::vector<std::string> details;
boost::split(details, res , boost::is_any_of(","));
// If I iterate through the vector there is only one element "John" and not all ?
迭代后我只得到名字而不是完整的细节
【问题讨论】:
-
details.size()的值是多少?拨打boost::split之后? -
我已经更新了这个问题。我也得到大小为 1