我试图转换为Linux/MacOS编写的C + + 14应用程序。它使用boost :: filesystem,但不用于某些iostream操作。例如:iostream GCC错误,转换为Windows :: boost :: filesystem :: iostream
boost::filesystem::path file = name;
std::ifstream fin(file.c_str());
此代码是无法编译在Windows上使用MinGW的10 GCC 6.3以下:
error: no matching function for call to 'std::basic_ifstream::basic_ifstream(const value_type*)' std::ifstream fin(file.c_str());
我想如果我可以转换的std :: ifstream的提振::文件系统:: ifstream的我能得到它的工作...所以我改变了代码,以这样的:
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);
导致这种错误:
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());
它看起来像我不能重新分配boost :: filesystem :: ifstream一旦创建......我能够将该行更改为以下,并编译,但我想知道如果它是正确的方法做到这一点:
boost::filesystem::ifstream fin(file.c_str());
奖金的问题:如果在Linux上此代码的工作,以及一旦我得到它的工作?
什么是'name'?你可以把它传递给'ifstream'构造函数吗? –