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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.