Originally Posted by
skatamatic
ifstream inFile;
vector<string> data;
inFile.open("File.txt");
while (!inFile.eof())
{
string sString = inFile.getline();
data.push_back(sString);
}
Don't bother with eof(), and don't put declarations in loops.
Simplified:
ifstream file("name");
vector<string> lines;
string str;
if(file.is_open())
{
while(getline(file, str))
{
lines.push_back(str);
}
file.close();
}
else
{
failed. set error events, logs, etc.
}
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert