I'm attempting to convert an app written in C++14 for linux/MacOS. It uses boost::filesystem, but not for certain iostream operations. For example:
boost::filesystem::path file = name;
std::ifstream fin(file.c_str());
This code was failing to compile on Windows 10 using MinGW with GCC 6.3 with the following:
error: no matching function for call to 'std::basic_ifstream::basic_ifstream(const value_type*)' std::ifstream fin(file.c_str());
I thought if I could convert the std::ifstream to boost::filesystem::ifstream I could get it to work... So I changed the code to this:
boost::filesystem::path file = name;
boost::filesystem::ifstream fin(file.c_str());
if (!fin)
{
file = pathToAppData / "files/expansion/assets/resources/basestation/config/mapFiles/racing" / name;
fin = boost::filesystem::ifstream(file.c_str());
if (!fin)
throw std::runtime_error(std::string("Cannot open Anki Overdrive map file ") + file.string() + ".");
}
fin >> (*this);
That resulted in this error:
error: 'const boost::filesystem::basic_ifstream& boost::filesystem::basic_ifstream::operator=(const boost::filesystem::basic_ifstream&) [with charT = char; traits = std::char_traits]' is private within this context
fin = boost::filesystem::ifstream(file.c_str());
It looks like I can't re-assigned a boost::filesystem::ifstream once created... I was able to change that line to the following and it compiled, but I'm wondering if it's the correct way to do it:
boost::filesystem::ifstream fin(file.c_str());
Bonus question: Should this code work on linux as well once I get it working?