从问题How to open an std::fstream with a unicode filename @jalf指出,C++标准库不是Unicode知道,但有一个窗口延伸接受wchar_t数组。
您将能够通过在wstream_t数组作为参数的fstream对象上创建或调用open来打开Windows平台上的文件。
fstream fileHandle(L"δ»Wüste.txt");
fileHandle.open(L"δ»Wüste.txt");
上述两种将调用的wchar_t *的相应的功能的版本,如在串将L前缀指示其是被当作一个Unicode字符串。
编辑:这是一个应该编译和运行的完整示例。我在我的计算机上创建了一个名为δ»Wüste.txt
的文件,其内容为This is a test.
然后我编译并在同一目录中运行以下代码。
#include <fstream>
#include <iostream>
#include <string>
int main(int, char**)
{
std::fstream fileHandle(L"δ»Wüste.txt", std::ios::in|std::ios::out);
std::string text;
std::getline(fileHandle, text);
std::cout << text << std::endl;
system("pause");
return 0;
}
的输出是:
This is a test.
Press any key to continue...
@Ephphatha看到的,这个问题的描述正确。它不是重复的。 – 2011-04-20 09:00:44
它看起来和我完全一样,但无论如何我都会回答。 – Ephphatha 2011-04-20 09:05:03
文件名固有地系统特定,并且取决于底层文件系统支持的内容。该语言无法定义。 – 2011-04-20 09:47:19