Help on File I/O

This is a discussion on Help on File I/O within the C++ Programming forums, part of the General Programming Boards category; I am a first semester programmer @ FSU. I am having a little trouble on a portion of an assignment ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Help on File I/O

    I am a first semester programmer @ FSU. I am having a little trouble on a portion of an assignment about File I/O.

    We are supposed to ask the user what the name of the file is and then open the file and do something with the it, as well as check and see if the file is open. I am having trouble on the getting the file name part, and then opening the file.

    The code I have is

    Code:
    ifstream inputFile;
    stream fileName;
    
    ...
    
    cout << "Please enter the name of the file you wish to decode: ";
    	cin  >> fileName;
    
    	inputFile.open(fileName);
    		
    		while (!inputFile){
    
    		cout << "Error reading file!" << endl;
    		cout << "Please try again: " << endl;
    		cin  >> fileName;
    		}

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try "string" fileName, instead of "stream" fileName.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    I actually do have that, I was just in the computer lab and was typing the post really fast cause they were closing down. *slap against the head*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-31-2004, 12:21 AM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 09:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21