Two questions in C++

Sharky Forums


Results 1 to 3 of 3

Thread: Two questions in C++

  1. #1
    Tiger Shark AMD Inside's Avatar
    Join Date
    Jul 2002
    Posts
    796

    Two questions in C++

    What would be the easiest way to output text to the console from a file?

    If the file was this:

    This is
    the
    file I am reading

    cout should print that to the console. Is there an echo command? or would I use getline?

    Also, how can I accept a file from the command prompt?

    Code:
    cout << "Enter a filename";
    cin >> file;
    
    ifstream inFile;
    inFile.open(file);
    does not work.
    Currently using:
    Gigabyte nForce 570
    Phenom 940 II 3.0GHz
    4GB DDR2
    Geforce 8800GT
    Audigy


    To Do List:

    Fix the car!

  2. #2
    Hammerhead Shark
    Join Date
    Jun 2003
    Posts
    1,019
    you opened the file but didnt do anything with it you can retrieve data from the file via ifstream through various methods such as:
    string temp;
    inFile >> temp
    or getline(inFile, temp)

    a simple google search of ifstream or c++ file io should give clear help

    as far as accepting from command prompt, you just use command line parameters. The very first search result of this gave an example of reading a file using a command line argument

  3. #3
    Tiger Shark AMD Inside's Avatar
    Join Date
    Jul 2002
    Posts
    796
    Yes, I figured out what I had to do and realized these were pretty n00bish questions. Oh well.
    Currently using:
    Gigabyte nForce 570
    Phenom 940 II 3.0GHz
    4GB DDR2
    Geforce 8800GT
    Audigy


    To Do List:

    Fix the car!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •