0

I'm having a simple i/o with file problem. I have the name coming from a string but it just wont open at all. Incoming code:

string notename[] = {"NULL","empty"};
ifstream readnote;

readnote.open(notename[x].c_str(),ios::in|ios::out);
        if(!readnote)
        {
            cout << "Read Error";
        }

its prolly something small but i keep getting the error, can u see it?

2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by CreatorZeus
1

What's the value of x? Neither of the values in notename suggest a valid file name, and if they do, you'd need to verify that the file is in the current working folder. I'd suggest trying perror to get more information on why the file didn't open successfully:

if (!readnote)
{
    perror("Read Error");
}

You can find perror in stdio.h.

Edited by deceptikon

0

x = 1;
oh god i feel like such a idiot... forgot the folder place of the file...

Edited by CreatorZeus: solved it

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.