I'm having trouble with linking a file in xtools. I've tried using the file directory from the prompt and putting it with the built exe but that doesn't work. I've also tried linking it with just
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
usingnamespace std;
int main()
{
ifstream in;
double next, sum, count, average;
ifstream in_stream;
in_stream.open("number.txt");
in>>next;
while (in_stream>>next)
{
sum= sum+next;
count++;
average = sum/count;
}
cout<< "The average of the data is "<<average<< endl;
return 0;
}
Is it "number.txt" ? The problem isn't the linking of the file. the problem is that you declared 2 separate ifstreams.
1 2 3
ifstream in;
ifstream in_stream;
Then you use one of them to open the file but then you use the other to try to extract information from the stream. Remove ifstream in_stream and just use in. Thus:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
usingnamespace std;
int main()
{
ifstream in;
double next, sum, count, average;
in.open("number.txt");
in>>next;
while (in >> next)
{
sum= sum+next;
count++;
average = sum/count;
}
cout<< "The average of the data is "<<average<< endl;
return 0;
}