Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ fstream未打开路径名中带有重音符号的文件_C++_Exception_Visual Studio 2012_Fstream - Fatal编程技术网

C++ fstream未打开路径名中带有重音符号的文件

C++ fstream未打开路径名中带有重音符号的文件,c++,exception,visual-studio-2012,fstream,C++,Exception,Visual Studio 2012,Fstream,但这不是我想要的:如果可能的话,我想将failbit设置为正常 我正在使用Visual Studio 2012和Windows 8。您确定可以使用窄字符串吗?源文件编码是什么?很可能与文件系统使用的Windows编码不匹配。@在posix/linux中允许使用chris。UTF-8@njr,是的,但它是Windows 8:p这就解释了,因为根据这个答案:Windows文件名(在NTFS上)存储为UTF-16,因此需要使用wchar\u t,因为ANSI版本的Windows函数不理解UTF-8。

但这不是我想要的:如果可能的话,我想将failbit设置为正常


我正在使用Visual Studio 2012和Windows 8。

您确定可以使用窄字符串吗?源文件编码是什么?很可能与文件系统使用的Windows编码不匹配。@在posix/linux中允许使用chris。UTF-8@njr,是的,但它是Windows 8:p这就解释了,因为根据这个答案:Windows文件名(在NTFS上)存储为UTF-16,因此需要使用wchar\u t,因为ANSI版本的Windows函数不理解UTF-8。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char **argv) {

    try
    {
        ifstream file;
        string simplePath = "I:/foo.conf";
        string markPath = "I:/Folder_à/foo.conf";

        file.exceptions(ifstream::failbit | ifstream::badbit | ifstream::eofbit);     

        file.open(simplePath.c_str());  // ok
        file.open(markPath.c_str());    // exception ios_base::failbit set
    }

    catch (ifstream::failure f)
    {
        cout << "Exception " << f.what() << endl;
        return 1;
    }

    return 0;
}
file.exceptions(ifstream::badbit | ifstream::eofbit); // removed failbit from the mask