help with reading from files : fstream library

Hello!
I don't know how to read from a file and I have to rewrite my program.
I know I have to include the fstream library.Could you help me please with this ??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream.h>
using namespace std;

int main()
{
	int capete,c,i,n;
	int x = 11;
	cout << "n = ";
	cin >> n ;
	if (n == 1) cout << "5" << endl;
	i = 2;capete = 5;
	while (i <= n) {
	x = capete + 6;
	capete = x-1;
	i++;
	} 
	cout << capete ;

return 0;
}


Open a file with fstream file("path.to.file"); and then replace cin >> with file >>.

Also, it's <fstream> with no .h

Also, what you're doing is weird. Isn't this just cin >> n; cout << 5*n;?
^ Wouldn't it be ifstream file("pathto.file");?
Or "path/to/file" or whatever you like.
@hamsterman Yes,it's just a little bit weird.Indeed,it is 5*n. I haven't realised it until now.Thank you very much.I have found this problem in a book and I have tried to solve it without realising that the answer is a multiple of 5. :))
Last edited on
Topic archived. No new replies allowed.