Where do inStream variables get assigned?

This is a discussion on Where do inStream variables get assigned? within the C++ Programming forums, part of the General Programming Boards category; Hello, I have written a short program to test this question but my program isn't working. It says tell what ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Exclamation Where do inStream variables get assigned?

    Hello,
    I have written a short program to test this question but my program isn't working.

    It says tell what values will be assigned to these variable when executed.

    inStream >> num1 >> num2;
    inStream >> num3;
    inStream >> num4;

    the int and inStream is an ifstream connected to a file containing the following data:
    1 -2 3
    4 -5 6
    7 -8 9

    I understand it should be reading values 1 -2 ,3 and 4 into num1 thru num4 but my program does not prove that. What have I done wrong?
    [code]
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cassert>
    using namespace std;

    int main()
    {

    // input section

    cout << "Enter the name of the input file: ";
    string inputFileName;
    getline(cin, inputFileName);

    ifstream inStream;
    inStream.open(inputFileName.data());
    assert(inStream.is_open());
    int num1, num2, num3, num4;

    inStream >> num1 >> num2;
    inStream >> num3;
    inStream >> num4;

    inStream.close();

    // output section

    while(getchar() != '\n');

    cout << "Enter the name of the oputput file: ";
    string outputFileName;
    getline(cin, outputFileName);

    ofstream outStream(outputFileName.data());
    assert(outStream.is_open());
    outStream << num1 << num2 << num3 << num4;
    outStream.close();
    cout << "Processing complete.\n";
    return 0;
    }

    [\code]
    Last edited by correlcj; 10-18-2002 at 02:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 11:02 AM
  3. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  5. why automatic variables are assigned with garbage values
    By srinivasg in forum C Programming
    Replies: 1
    Last Post: 11-08-2005, 06:14 AM

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