Thread: capturing program input

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    109

    capturing program input

    For my program I used csis statements like

    Code:
    cout<< "Hello" << endl;
    csis<< "Hello" << endl;
    I put all the required statements in like csis.open("csis.dat") and csis.close
    but I don't get why when I look at my csis.dat file it only shows what the program outputs and it doesn't capture the input that I put in when the program runs. How do I make it so that both the output and the input are captured? Thanks

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If csis is just an ofstream that you opened, then it's only going to write what you tell it to write. Am I missing something? This seem like a silly question to assume data will be automatically written to a file that you haven't explicitly sent to be written.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    109
    Quote Originally Posted by MacGyver View Post
    If csis is just an ofstream that you opened, then it's only going to write what you tell it to write. Am I missing something? This seem like a silly question to assume data will be automatically written to a file that you haven't explicitly sent to be written.
    I know that. My question is how do I capture the input that I put in when I run the program? How do I get the input into the csis.dat file?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Just write it. I don't know. Something like:

    Code:
    cin >> somevar;
    csis << somevar;
    Depends on how you're reading your data and how you want it formatted.

  5. #5
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by MacGyver View Post
    Just write it. I don't know. Something like:

    Code:
    cin >> somevar;
    csis << somevar;
    Depends on how you're reading your data and how you want it formatted.
    Maybe a bit off-topic, but does C++ allow this:

    Code:
    cin >> csis
    Or do you have to use a variable like you did?

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    No, but if it was allowed, how would the data be parsed? What would be written to csis?

    Another thing is that he probably wants to do something with the variable other than just write it to the file.

  7. #7
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by MacGyver View Post
    Another thing is that he probably wants to do something with the variable other than just write it to the file.
    Surely, so it would be useless anyways, i was just a bit curios..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Utter newb?: Program crashes after input
    By deductible in forum C++ Programming
    Replies: 5
    Last Post: 12-13-2008, 10:27 PM
  3. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM
  4. provide input to another program
    By oncemyway in forum C Programming
    Replies: 14
    Last Post: 07-31-2005, 04:12 PM
  5. Input via the serial port for a C program
    By Anthony in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2005, 02:19 PM