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
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()
)
Thanks I solved it with changing the extention to txt