I am confused with this code that somebody gave me
I was given this code from a thread that I created (i cannot remember who) and I would like somebody (preferably the same person who gave it to me) to explain what each line does ('cause i've got no idea). And also, when I compile it (in MSVC++ 6.0), it does nothing but sit there!! It is meant to display all of the lines of a text file. I really wanted it to store each line in a variable if it wasn't empty, but anyway.....
...here is the code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream file("myfile.txt"); // or whatever
vector<string> Lines;
string CurrentLine;
while(!file.eof())
{
getline(file, CurrentLine);
if(!CurrentLine.empty()) // store it if not empty
Lines.push_back(CurrentLine);
}
// show the stored lines
for(int i = 0; i < Lines.size(); i++)
cout << Lines[i] << endl;
file.close();
return 0;
}
Thanks heaps
-Chris