Contact Us

Scripts: Cplus :: C++ string functions :: Library Article #2

Developer's Section

Read a file in C++
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1661)

Learn how to read a file in C++

This article shows you how to read a file and place the contents of the file in a vector string:

 Code Snippet 1

int main()
  //Read the Content of a file 

  static vector<string> myfile;
  ifstream inf("myfile.txt"); // using fstream to read file
  string data;
  int currLine = 0;

  while(!getline(inf, data).eof())
    myfile[currLine] = data;
  return 0;


See other Scripts in C++ string functions

Submit Your Scripts:

If you would like to have your C++ scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]