我将使用boost::split来解析一个数据文件。数据文件包含如下所示的行。
对于上面的代码行,我应该得到 5 的输出,但我得到了 6。我已经尝试阅读文档,这个解决方案似乎应该实现我想要的功能,显然我漏掉了什么。谢谢!
编辑: 在 dataLine 上运行以下 for 循环,您将得到以下结果。
data.txt
1:1~15 ASTKGPSVFPLAPSS SVFPLAPSS -12.6 98.3
这些项目之间的空格是制表符。我拆分上述行的代码如下。
std::string buf;
/*Assign the line from the file to buf*/
std::vector<std::string> dataLine;
boost::split( dataLine, buf , boost::is_any_of("\t "), boost::token_compress_on); //Split data line
cout << dataLine.size() << endl;
对于上面的代码行,我应该得到 5 的输出,但我得到了 6。我已经尝试阅读文档,这个解决方案似乎应该实现我想要的功能,显然我漏掉了什么。谢谢!
编辑: 在 dataLine 上运行以下 for 循环,您将得到以下结果。
cout << "****" << endl;
for(int i = 0 ; i < dataLine.size() ; i ++) cout << dataLine[i] << endl;
cout << "****" << endl;
****
1:1~15
ASTKGPSVFPLAPSS
SVFPLAPSS
-12.6
98.3
****
boost::algorithm::trim
变体是否不足够? - Dan Lecocq