Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 使用boost文件系统C+逐行读取文件+;_File_Parsing_Boost_Filesystems - Fatal编程技术网

File 使用boost文件系统C+逐行读取文件+;

File 使用boost文件系统C+逐行读取文件+;,file,parsing,boost,filesystems,File,Parsing,Boost,Filesystems,我正在使用boost::filesystem库打开具有特定路径的文件file\u path: fs::ifstream file(file_path); string str; vector<string> filenames; while(getline(file, str)){ filenames.push_back(str); } fs::ifstream文件(文件路径); 字符串str; 矢量文件名; while(getli

我正在使用boost::filesystem库打开具有特定路径的文件file\u path:

 fs::ifstream file(file_path);
    string str;
    vector<string> filenames;
    while(getline(file, str)){
        filenames.push_back(str);
    }
fs::ifstream文件(文件路径);
字符串str;
矢量文件名;
while(getline(文件,str)){
文件名。推回(str);
}

此代码已在没有升压的情况下从常规C++代码中修改。起初,我正在读取当前目录中的一个文件,但我必须编辑路径。现在看来getline工作不正常。是否有一种替代getline的boost方法,以便我可以逐行解析文件并将它们读入向量


谢谢

boost::filesystem::ifstream
只是另一个输入流,所有标准算法应用于它的方式与应用于
std::ifstream
的方式相同<代码>标准::getline也可以使用它。

上面的答案绝对正确。如果有人想要完整的代码:

boost::filesystem::ifstream fileHandler(fileName);
string line;
while (getline(fileHandler, line)) {
    cout << line << endl;
}
boost::filesystem::ifstream fileHandler(文件名);
弦线;
while(getline(fileHandler,line)){

如果问题是在更改文件路径时开始的,则可能无法成功打开文件。您所说的“工作不正常”是什么意思?您需要发布代码、预期行为和实际行为。