Products
Services
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: (1734)
Favorites:

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

#include<vector>
#include<fstream>
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;
    currLine++;
  }
  return 0;

}


See other Scripts in C++ string functions

Submit Your Scripts:


System Message:
  • Your C++ script has been sent. Please allow 48 hours for processing.


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:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]