#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;
}
ファイルのパス名にアクセント記号(例:àopen()
)が含まれている場合、関数はios_base::failbit set
例外をスローします。
簡単な修正は
file.exceptions(ifstream::badbit | ifstream::eofbit); // removed failbit from the mask
しかし、私が望むものではありません。可能であれば、フェイルビットを通常どおりに設定したいと思います。
VisualStudio2012とWindows8を使用しています。