Thread: File I/O Problem

  1. #1
    Registered User
    Join Date
    Apr 2003

    File I/O Problem

    When I try to open a file it says it doesn't exist, but it really does though..

    Reader( string fileToRead );

    // To simplify the implementation, the user may either call "getLine" but
    // not "hasAnotherOpenAngledBracket" and "getToken" OR
    // call "hasAnotherOpenAngledBracket" and "getToken" but not "getLine".

    // Reads the next input line and stores it in "line". It returns ture
    // if "read" did not return eof. Otherwise, it returns false.

    #include <string>
    #include "Reader.hpp"
    // Copy the contents of "inputFileName" to standard output.
    // This program demonstrates the use of "Reader" and its
    // function, "getLine".
    int main( int argc, char *argv[] )
            if ( argc != 2 ) {
                    cout<< "usages: "<< argv[0] <<" <filename>\n\n";
     Reader reader(argv[1]);
    return 0;
    #include <iostream>
    #include "Reader.hpp"
    #include <fstream>
    using namespace std;
    Reader::Reader( string fileToRead)
       ifstream inFile;
         cout << "Error: " << fileToRead  << " does not exitst!" << endl;

  2. #2
    Registered User
    Join Date
    Aug 2005
    Quote Originally Posted by gqchynaboy
    When I try to open a file it says it doesn't exist, but it really does though..
    Ah -- but does it exist in the current working directory? Try entering the full path to the file on the command-line when you run the program. will not search your hard drive for you to find the file, it either wants the full path or wants the file in the program's current working directory.

  3. #3
    Registered User
    Join Date
    Jan 2005

    That code is attempting to open a file called "fileToRead" and is ignoring the input parameter of the same name. Whatever you are adding to the comand line is being ignored. It should be:;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File i/o problem
    By tezcatlipooca in forum C++ Programming
    Replies: 18
    Last Post: 01-01-2007, 09:01 AM
  2. File I/O problem
    By Onions in forum C++ Programming
    Replies: 41
    Last Post: 02-24-2006, 04:32 PM
  3. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 12:14 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM