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]