Problem creating an output file

So I'm trying to make this program create an output file instead of displaying it on the console. Everything compiles fine, but it still displays the output and doesn't create an output file. I thought the code I wrote was write, but I'm apparently wrong. Any help in figuring this out would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  #include<iostream>
#include<fstream>  
#include<cstdlib>
#include<cmath>
using namespace std;

int main()
{
	int x, count = 0;
	float sum = 0, avg;
	char input_file[15]; 
	char output_file[15];

	ifstream in_s;  
	cout << "Please input the input file name \n"; 
	cin >> input_file;

	in_s.open(input_file); 
	if (in_s.fail())
	{
		cout << "Input file opening failed. \n";
		exit(1); 
	}
	out_stream.open(output_file);
	if (out_stream.fail())
	{
		cout << "Output file opening failed. \n";
		exit(1);
	}
	outstream << "\t  x \t\t x^2 \t\t Current Sum \n";
			  << "\t === \t\t === \t\t ========== \n";

	while (in_s >> x) 
	{
		sum = sum + x;
		cout << "\t  " << x << "\t\t  " << pow(x, 2) << "\t\t  " << sum << "\n";
		count++;
	}

	avg = sum / count;
	outstream << "\n \t\t The average of these " << count << " numbers is: " << avg << endl;

	in_s.close();  
	out_stream.close();
	return 0;
}
You have to declare your out_stream variable before you open the file.
ofstream out_stream;
And lines 30 and 41 are missing the underscore in out_stream.
Topic archived. No new replies allowed.