Advertisement
file-stream-object.open("filename", mode);
File Mode | Description |
---|---|
ios::in | This mode searches for a file and opens it in the read only mode, and next we could use the get() input function to read the content of a file. |
char get(void)
Advertisement
Gender : Female
Age : 28
City : India
Weight : 60.6 Kg
//C++ Reading the content to a file using ifstream class and file mode ios::in
#include<iostream>
#include<ifstream>
using namespace std;
int main()
{
//Creating an input stream to read a file
ifstream ifstream_ob;
//Opening a file named File1.txt to read its content
ifstream_ob.open("File1.txt", ios::in);
char ch;
//Reading the file using get() function and displaying its content
while(ifstream_ob)
{
ch = ifstream_ob.get();
cout<<ch;
}
//Closing the input strea
ifstream_ob.close();
return 0;
}
GendXr : Female
Age : 28
City : India
Weight : 60.6 Kg
Executing this program will read the content of a file named File1.txt(present in the current directory),
by using the get() function.
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement