Reading from console window...

This is a discussion on Reading from console window... within the C++ Programming forums, part of the General Programming Boards category; can someone help me figure out what i'm doing wrong here: everything else works fine so i'm just giving parts ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    124

    Reading from console window...

    can someone help me figure out what i'm doing wrong here:
    everything else works fine so i'm just giving parts of the code...
    here's part of my main function:

    Code:
    int main(int argc, char* argv[])
    {        
            char *fname;
            
            ifstream file;
            fname = argv[1];     
            aStarSearch.readFile(fname);  //function in a class which needs the argument to main from the console window
    ....
            return 0;
    }
    Here's part of the code from the readFile function:

    Code:
    void readFile(char *openfile)
    {
               ifstream fin (openfile);
               while (! fin.eof() )
               {
    
               }
    }
    The problem is that when the console window open up, i can't type anything there...if i hardcode the name of the file to be opened it works fine but in that case the console window doesn't really come into play because it doesn't expect any inputs from the user...

    am i using this wrong?

    Regards,

    Farooq

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    actually just checked and it's not accepting inputs in any case...i just used this code in main:

    Code:
          int ix;
          for (ix = 0; ix < argc; ix++) 
          printf("My %d. argument is %s\n", ix, argv[ix]);
    and the console window just prints this out...so im guessing that's where you basically get your outputs and all...i was thinking more like the DOS thing...i give it some input and then i get output? do i have to run this using dos?

    Regards,

    Farooq

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You do realise that nothing in your code actually asks for any input, right? All your code does is take whatever you put on the command line as the file name, and then it processes it. There is no user input, because you don't ever actually try to read anything from the user. You have no cin or scanf or whatever. It's only output and your file you specify on the command line.

    You processing the argv is not getting input from the user. It's processing what is passed via the command line:

    c:\mystuff\> filename commandlineargument

    See?

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console window in VC 2008
    By swgh in forum Tech Board
    Replies: 0
    Last Post: 06-05-2008, 03:13 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. Output to console window...
    By alvifarooq in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2004, 08:56 PM
  5. Picking up characters in console window
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 11-03-2002, 05:21 PM

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