Hey, I have started working with I/O file streams using my 'problem solving with c++' book, I am not sure where the .dat file goes in MS Visual C++ or how to make it for that matter...
Also is this code correct? I am getting strange errors...
I am trying to output the largest number from a file to the screen.
#include "stdafx.h"
#include <fstream> // file stream
#include <iostream> // for cout
#include <cstdlib>// exit
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream in_stream; // input file stream
//ofstream out_stream;
in_stream.open("infile.dat"); // open infile.dat file
if (in_stream.fail( ))
{
cout << "Input file opening failed.\n";
exit(1);
}
//out_stream.open("outfile.dat")
int res;
int num1, num2, num3;
in_stream >> num1 >> num2 >> num3; // each line is read from the file
cout << "The largest number in the infile.dat file is: ";
cout << max(num1, num2, num3); // the biggest number is calculated and output;
res = num1 + num2 + num3;
cout << res;
cout << endl;
in_stream.close();
return 0;
}
Thank you for any help!