Pages

Thursday, December 5, 2013

file reading character by character in C++




//#include "stdafx.h" used when compiling in Visual Studio 2012

#include<fstream>
#include<iostream>
using namespace std;


int main(){


ifstream is;//made an object of input file stream to read from file character by character

char character;

is.open("myfile.txt");//make a file of any name instead of myfile.txt in compiler directory

is>>character;
while(!is.eof() && !is.fail()){
cout<<character;
is>>character;
}
is.close();
cout<<endl;
return 0;
}

No comments:

Post a Comment