A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ program to read a text file
Q:

C++ program to read a text file

0

C++ program to read a text file

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to read text character by character in C++

#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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now