虽然下面的代码在Linux上编译,但我无法在Windows上编译它:boost :: filesystem :: path :: native()返回std :: basic_string <wchar_t>而不是std :: basic_string <char>
boost::filesystem::path defaultSaveFilePath(base_directory);
defaultSaveFilePath = defaultSaveFilePath/"defaultfile.name";
const std::string s = defaultSaveFilePath.native();
return save(s);
其中base_directory是一个类的属性,它的类型是std :: string,而函数save只需要一个const std :: string &作为参数。编译器抱怨第三行代码:
错误:从'const string_type {aka const std :: basic_string}'转换为非标量类型'const string {aka const std :: basic_string}'请求“
对于这个软件,我用两个升压1.54(对于某些公共库)和Qt 4.8.4(为使用这个公共库的UI)和我都编译使用MinGW GCC 4.6.2。
如果我的评估是正确的,我会问你:我该如何使std :: stri的Boost返回实例返回实例如果我的Windows Boost构建返回std :: basic_string NG?顺便说一句,有可能吗?
如果我对这个问题做了一个糟糕的评估,我请你提供一些关于如何解决这个问题的见解。
干杯。
谢谢你,这是真的很有帮助。你能提出一种方法来使这个代码更加便携吗?我是否应该将我的字符串声明为文件系统路径作为boost :: filesystem :: path :: string_type贯穿我的代码?这里有什么好的做法? – Ramiro
这取决于你想要对路径做什么。最便携,但限制最多的是坚持'filesystem :: path'并使用boost提供的文件操作和iostream功能。如果你需要更具体的东西,你会失去可移植性,但会获得灵活性。 –