Reading error data from file

Aug 30, 2009 at 11:50am
Hi

This is the code that i practice below
********************************************************************************
#include <fstream>

int main()
{
using namespace std;
ifstream in;
ofstream out;
in.open("in.text");
out.open("out.text");

int first,second,third;

in >> first >> second >> third;
out << "Thesum of the first 3\n"
<< "numbers in infile.dat\n"
<< "is" << (first+second+third)
<< endl;

in.close();
out.close();
return 0;
}
*******************************************************************

In the in.text,the data is shown as below
1
2
3
4

My question is that why i get the answer like below in out.text file

Thesum of the first 3
numbers in infile.dat
is2293672

which should be answer of 6.

Why the program read the wrong value of varibles

Thanks
Aug 30, 2009 at 11:57am
It works for me. Check if the file is in the correct place, check if the program could actually open the file (in.is_open())
Aug 30, 2009 at 11:17pm
Thanks I solved it with changing the extention to txt
Topic archived. No new replies allowed.