Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a file line by line with boost filesystem C++

I'm using the boost::filesystem library to open a file with a specific path file_path:

 fs::ifstream file(file_path);
    string str;
    vector<string> filenames;
    while(getline(file, str)){
        filenames.push_back(str);
    }

This code has been adapted from regular C++ code without boost. I initially was reading in a file placed in my current directory but I had to edit the path. Now it appears that getline is not working correctly. Is there a boost alternative to getline so that I can parse the file line by line and read them into the vector?

Thanks!

like image 820
jonnyd42 Avatar asked Dec 24 '22 10:12

jonnyd42


1 Answers

boost::filesystem::ifstream is just another input stream, and all standard algorithms apply to it the same way they apply to std::ifstream. std::getline works with it as well.

like image 74
Andrey Semashev Avatar answered Dec 29 '22 02:12

Andrey Semashev