C++ examples for File Stream:File Operation
Copy an entire file into a vector of string
#include <string> #include <iostream> #include <fstream> #include <vector> using namespace std; int main() {/*from w w w . j a v a2 s . c o m*/ vector<string> v; ifstream in("main.cpp"); string line; while(getline(in, line)) v.push_back(line); // Add the line to the end for(int i = 0; i < v.size(); i++) cout << i << ": " << v[i] << endl; }