Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,924 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,807 people online right now. Registration is fast and FREE... Join Now!




help to load data from text file

 
Reply to this topicStart new topic

help to load data from text file

krish_smartroy
1 Apr, 2008 - 12:43 AM
Post #1

New D.I.C Head
*

Joined: 31 Mar, 2008
Posts: 1

Actually i want to learn about the load data from text file code and whatever is loaded which way we will display that data in c++. if you can help me then please tech me very briefly that with the code anykind of example. I don't mind. but i want to be perfect in this matter.

This post has been edited by krish_smartroy: 1 Apr, 2008 - 12:45 AM
User is offlineProfile CardPM
+Quote Post

realNoName
RE: Help To Load Data From Text File
1 Apr, 2008 - 01:25 AM
Post #2

D.I.C Regular
***

Joined: 4 Dec, 2006
Posts: 299



Thanked: 5 times
My Contributions
CODE
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file";

  return 0;
}


Working with files tutorial
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:17PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month