Thread: file io with variable

  1. #1
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163

    file io with variable

    I want the user to enter then name of the file to open so i did this basicly

    cin>>name; /* this isnt real code */
    ifstream ifile;
    ifile.open(name)
    blah

    but it doesnt work...how would I do this?
    +++
    ++
    + Sekti
    ++
    +++

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    char filename[80];
    cin.getline(filename,79,'\n');
    ifstream input;
    input.open(filename);
    if( input.fail() )
    {
    cout << "Error with file " << filename << endl;

    }
    else
    {
    //do whatever you want with the file
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 10:18 AM