File name with whitespace: Can not read!

Hi,

I am using the code:

1
2
3
4
5
6
7
8
9
string f = m.getfilename();
    cout << "Arquivo: " << f << " ";
    iFile.open(f.c_str());
    if (!iFile) { // file couldn't be opened
        std::cerr << "Error: file could not be opened" << endl;
        exit(1);
    } else {
        //        cout << "Abrindo arquivo: " << m.getfilename() << endl;
    }


where

ifstream iFile;

This works but when the file name has a space like in "file 2.dat", then this code fails to read the file.

What I can do to overcome this little bug?
I think that may be there is a '\0' in string f, so f.c_str() is not the really file name.
you can step into iFile.open() method to watch the file name.
What is the code inside getfilename ?
I guess getfilename() is not returning the filename u expect
Topic archived. No new replies allowed.