我正在做一些实验,以更好地理解转换,并且下面的代码无法按预期工作
std::wstring inScriptPath = "non-ASCII file name"
using convert_type = std::codecvt_utf8_utf16<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
std::string my_path = converter.to_bytes(inScriptPath);
std::fstream myfile;
myfile.open(my_path.c_str(), ios::in); //open the file
if (myfile.is_open()) {
std::cout << "Openning file for reading with fstream" << std::endl;
myfile.close();
}
FILE * pFile;
pFile = fopen(my_path.c_str(), "r");
if (pFile != NULL)
{
std::cout << "Openning file for reading with fopen" << std::endl;
fclose(pFile);
}
我希望将wstring转换为字符串文件后,open / fopen应该可以工作,但是不能工作。我在做什么错?