I'm reading values from an input text file that I have no control over. The first line is an integer representing the number of the lines to follow. Each of those lines to follow contains one of 3 characters that can be found in the next enum:
enum Size {
S,
M,
L
}
The ifstream can't insert the value directly into a Size datatype. So the following code won't work to store all the values in a vector of the datatype Size
enum Size {
S,
M,
L
}
unsigned lines_count;
std::vector<Size> data;
file >> lines_count;
for (auto i = 0u; i < lines_count; ++i) file >> data[i]; // WRONG
So the values have to be stored into a char. I was wondering if there was a way to store the value into the datatype Size directly that RESEMBLES the following:
unsigned lines_count;
Size size;
char c;
file >> lines_count;
for (auto i = 0u; i < lines_count; ++i) {
file >> c;
size = Size::c // c resolves to either S, M, or L
data[i] = size;
}
I know that this syntax does NOT work. I just need the most concise way to do it instead of using a switch or if-statements.