#include<iostream> #include<fstream> #include<string> using namespace std; int main() { string strfile="filenamewithabsolutepath.txt"; ifstream ifptr; ifptr.open(strfile); if(!ifptr.is_open()) { cout<<"Unable to open file\n"; } else{ //read the file till the end while(!ifptr.eof()) { string line; getline(ifptr,line); cout<<"line:"<<line<<"\n"; }//end of while }//end of else return 0; }//end of main
Friday, 29 June 2012
Program to Read a file line by line in C++
Friday, 22 June 2012
Program to Reverse a String
Code:
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include<iostream> |
Output:
Original string:abcdefg Reverse string:gfedcba
Subscribe to:
Posts (Atom)