How come I can't open file by: string filename; inFile.open(filename); - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How come I can't open file by: string filename; inFile.open(filename);

jedi06jedi06 Posts: 38Member
int main(){

string filename;
cin>>filename;

ifstream inFile;

inFile.open(filename);

//operations here.

inFile.close();
)

Comments

  • dwccgcdwccgc Posts: 576Member
    [b][red]This message was edited by dwccgc at 2006-2-4 9:25:42[/red][/b][hr]
    : int main(){
    :
    : string filename;
    : cin>>filename;
    :
    : ifstream inFile;
    :
    : inFile.open(filename[red][b].c_str()[/b][/red]);
    :
    : //operations here.
    :
    : inFile.close();
    : )
    :
    :

    [blue]
    [b]from MSDN[/b]
    ifstream::open(...)
    Opens a disk file and attaches it to the streams filebuf object. If the filebuf object is already attached to an open file, or if a filebuf call fails, the ios::failbit is set. If the file is not found, then the ios::failbit is set only if the ios::nocreate mode was used.

    [/blue]





Sign In or Register to comment.