Pages

Friday, December 6, 2013

file reading using array

// filing.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

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


int main(){


ifstream is;//made an object of input file stream to read from file using array

char character[100];


is.open("ReadMe.txt");
is.getline(character,100,'\n');

while(!is.eof() && !is.fail()){
cout<<character;
is.getline(character,100,'\n');
}
is.close();
cout<<endl;
return 0;
}

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;
}