Read From File In C++

by Shabbir on June 7, 2008

in C/C++

In the previous tutorial we explained how to do that in C#, now we will do that in C++.
So, create a Win32 C++ Console Application. This tutorial will be similar to the tutorial for writing to file in c++,
So, write this code

 
int main()
{
	ifstream in;
	in.open("text.txt");
 
	char line[256];
 
	while(in.getline(line, 256))
	cout << line << endl;
 
	in.close();
}

Here we read the file line by line, and write its content to the console.
We have one char variable where we will store that lines, it will be long 256 characters. We are using the ifstream class, and creating an object from it, opening the file, do our work, and in the end we are closing the handle from our application to the file we read.
That's it. Very simple.

Share:
  • Digg
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
Other Related Posts:
  1. Write To File In C++
  2. Read From File Using StreamReader Class
  3. Write To File in C#
  4. ASP at a glance
  5. Using the Timer Class

Want More Tips on How to Make Money Online?
Enter your Name and Email below to subscribe and start 1 month free course now.

Name:
Email:
You would require to confirm your email address before we send you any updates. We respect your privacy as much as you do.
Powered by Aweber
blog comments powered by Disqus

Previous post:

Next post:

    About the Author

  • author photo

    My Name is Shabbir Bhimani and I am developer by profession in the field of applications, web and database. Currently doing full time online marketing and like to share my experiences on how you can make money online @ CodeItWell.com. Read more ...


    See how you can get in touch with me.