My code has a struct type like this:
1 2 3 4 5 6 7
|
struct entityOne
{
int id_entityTwo;
int id_entityThree;
string description;
bool isActive;
};
|
Then I have some CRUD operations on a vector of structs.
And I have 3 functions to read/write to a txt file: one of them writes one object to the file, one of them loads all file contents to a vector and the last one writes all vector items in the file.
I've included all of these:
1 2 3 4 5
|
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
|
But I'm getting an error with my function that loads items from file to vector:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void read_entities(vector<entityOne> &collection)
{
entityOne item;
ifstream afile(MYFILE);
if (!afile.is_open())
{
cout << "Can't open file" << endl;
}
else
{
while ((afile >> item.id_entityTwo) && (afile.ignore()) && (afile >> item.id_entityThree) && (afile.ignore()) && (getline(afile, item.description)) && (getline(afile, item.isActive)))
collection.push_back(item);
afile.close();
}
}
|
The error is thrown at the "while" line: "no matching function for call to 'getline(std::ifstream&, bool&)'"
I understand this is an error displayed when there's no definition for the function used (because I'm not using the right parameters).
But I've copied this code from a different project where I have a similar struct and the same kind of function and it compiles correctly. The difference in this working code is that it reads 2 string members and then an int member, like this:
|
while (getline(afile, book.name) && getline(afile, book.genre) && (afile >> book.isbn) && afile.ignore())
|
What could be wrong with my code?