#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;
}
If a file has an accent mark (e.g. à) within its pathname, the open()
function throwns a ios_base::failbit set
exception.
A simple fix is
file.exceptions(ifstream::badbit | ifstream::eofbit); // removed failbit from the mask
but is not what I want: if possible I'd like to set the failbit as normal.
I'm using Visual Studio 2012 and Windows 8.