belongs to collection: C++ programming File Handling/ File Streams Examples
#include<iostream> #include<fstream> using namespace std; int main() { char ch; const char *fileName="test.txt"; //declare object ifstream file; //open file file.open(fileName,ios::in); if(!file) { cout<<"Error in opening file!!!"<<endl; return -1; //return from main } //read and print file content while (!file.eof()) { file >> noskipws >> ch; //reading from file cout << ch; //printing } //close the file file.close(); return 0; }
Output
Hello friends, How are you? I hope you are fine and learning well. Thanks.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program to read text character by character in C++
Output