Given a method that I wrote on my own, a text file is given and I want to save the items into a vector<Object> referenceObject
. It works nearly, but if I got in my text file objects like, for example: " Book of light "
, it just saves "Book"
, so it stops reading on the first space.
I read some other StackOverflow questions like mine, but for my problem they don't work.
Question: It returns all objects of my text file, except for my first object. So my list starts by index=1
and not by index=0
. Why?
void openfile() {
ifstream inFile;
inFile.open("textfile");
if (inFile.fail()) {
cerr << "error open this file" << endl;
exit(1);
}
string item;
int count = 0;
vector<Object> referenceObject;
while (!inFile.eof()) {
while (getline(inFile, item)) {
inFile >> item;
Object s;
s.setName(item);
referenceCards.push_back(s);
std::cout << count << ' ' << referenceObject.at(count).getName() << endl;
count++;
}
}