I have a struct:
struct foo {
int a;
string b;
bool c;
//... ad infinitum
};
I want to load it with data in a .txt file, something like this:
string a, b, c;
string* ptr[] = { &a, &b, &c };
ifstream file("input.txt");
size_t i = 0;
while (file >> *ptr[i])
(i < 3) ? i++ : i = 0;
//convert a, c to int and bool, then assign
But then I would have to manually convert them from string to int or bool types, is there anyway to load all of them without the need to convert afterward (using void* ptr[] perhaps)?
I don't want like this:
while (!file.eof()){
file>>a;
file>>b;
file>>c;
}
Because Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?, and I don't want to file>>
10 times.
I also haven't learned things like lexical_cast or operator overload so any answer related to them is very helpful, but may not solve my problem.
Here's the txt file:
19127519
Jame Howard
0
19124567
Jacky Thomas
1
14527890
Lucas
1