Finding a linked file in xtools

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
using namespace 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;
}

but with no luck.

Any ideas anyone?
Which file are you trying to link?

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
using namespace 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;
}
Last edited on
Thank you, I've done the changes but it's still not picking up the file.
Is the file in the same directory as your main file?
yes. I've tried there and where the exe is located neither produced positive results.
Topic archived. No new replies allowed.