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

boostfilefilesystemsparsing

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!

Best Answer

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.