I have defined:
And I read content from a text file using
Why then should
throw an 'std::out_of_range' at runtime?
vector <string> _contents; int _lines; ifstream* _file; string _path;
And I read content from a text file using
bool File::_refresh(const string path)
{
_path = path;
_file = new ifstream(_path.c_str());
if (_file->is_open() != true)
{
_file = NULL;
return false;
}
//no of lines
_lines = 0;
_contents.clear();
while (_file->eof() == false)
{
string cur_line;
getline(*_file, cur_line);
_contents.push_back(cur_line);
_lines += 1;
}
_file->close();
return true;
}
Why then should
cout << _contents.back() << endl;
throw an 'std::out_of_range' at runtime?