我需要使用一些C++代码读取一个以制表符分隔的文本文件。该文件包含三列,第二列包含带有空格的字符串。以下是该文件的一些示例。
1 hellow world uid_1
2 good morning uid_2
以下是我需要使用的C++代码来读取文件。但是,当字符串中含有空格时,它无法正确地读取文件。
有什么修改while循环使其正常工作的建议吗?我对C++不熟悉。请提供详细的代码。谢谢!
#include <Rcpp.h>
#include <iostream>
#include <fstream>
#include <string>
std::ifstream infile (file_name.c_str());
int row = -1;
std::string col;
std::string uid;
while (infile >> row >> col >> uid) {
### operations on row, col and uid ####
}