mvc*_*mvc 2 c++ homebrew clang msys2
我在MacOS中使用brew安装了clang 15.0.7,并在Windows 10中使用MSYS2安装了相同版本。
当我编译以下程序时:
#include <filesystem>
int main()
{
std::filesystem::path p("/some/path");
std::string s(p);
}
Run Code Online (Sandbox Code Playgroud)
使用clang++ -std=c++20 test.cpp
我在 MacOS 上没有得到编译错误,但在 Windows 中它给出:
test.cpp:6:15 error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
std::string s(p);
^ ~
[more errors]
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?
std::filesystem::path::value_type
在wchar_t
Windows 和char
其他地方。
因此,在Windows 上和其他地方std::filesystem::path
有一个转换运算符(谁甚至认为这是一个好主意?!)。std::wstring
std::string
打电话以“便携”的方式.string()
获取。std::string
在 Windows 上,请确保测试您感兴趣的所有标准库风格(MSVC STL、GCC 的 libstdc++、Clang 的 libc++)的 UTF-8 支持。我记得至少在 MSVC 上您必须启用区域设置的 UTF-8 支持,或者使用std::u8string
.