ifstream and ofstream

Hi, what is the usage of ifstream and ofstream ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>

int main()
{
	float val1, val2, val3, val4, average, add;
   ifstream inData;
   ofstream outData;

   inData.open("DataIn.txt");
   outData.open("DataOut.txt");

   inData >>val1>>val2>>val3>>val4;
   add=val1+val2+val3+val4;
   average=add/4;
   outData<<"Average of 4 number is: "<<average;
   return 0;
}
ifstream - read from file
ofstream - write to file
Ok...thanks
for the line 10 and 11, the code "inData.open", is that fixed? or i can change it to "abc.open" by changing the "ifstream inData" to "ifstream abc"?
Yes inData is just the variable name. You can name it whatever you want.
Ok...Thanks peter^^
Topic archived. No new replies allowed.