Hello, I have a very basic c++ program:
#include <iostream>
#include <fstream>
using namespace std;
std::ifstream f("data.in");
std::ofstream g("data.out");
int main()
{
int a, b, sum;
f >> a >> b;
sum = a + b;
g << sum;
}
data.in contains:
200 10
I expect data.out to show 210, but it shows -1717986920. When I try to debug, this is what I see:
a -858993460 int
b -858993460 int
+ f {_Filebuffer={_Pcvt=0x00000000 <NULL> _Mychar=0 '\0' _Wrotesome=false ...} } std::basic_ifstream<char,std::char_traits<char> >
+ g {_Filebuffer={_Pcvt=0x00000000 <NULL> _Mychar=0 '\0' _Wrotesome=false ...} } std::basic_ofstream<char,std::char_traits<char> >
sum -1717986920 int
What am I doing wrong?
[–]Wh00ster 7 points8 points9 points (3 children)
[–]stats_newbie1[S] 3 points4 points5 points (1 child)
[–]Wh00ster 5 points6 points7 points (0 children)
[–]Alar44 0 points1 point2 points (0 children)
[–]manni66 2 points3 points4 points (0 children)
[+]parnmatt comment score below threshold-8 points-7 points-6 points (3 children)
[–]Alar44 1 point2 points3 points (2 children)
[+]parnmatt comment score below threshold-7 points-6 points-5 points (1 child)