I was reading in Bjarne Stroustrup's "Principle and Practice Using C++" when I encountered the following example, where we are reading from a file.
1 2 3 4 5
0 60.7
1 60.6
2 60.3
3 59.22
q
1 2 3 4 5 6 7 8 9 10
struct Reading {
int hour;
double temperature;
ifstream ist{"filename.txt"};
vector<Reading> temps; //store readings here
int hour;
double temperature;
while (ist >> hour >> temperature) //when exactly does this terminate?? When there is no longer an int and a double per line?
temps.push_back(Reading{hour, temperature});
I am also wondering about the syntax of adding instances of the Reading-struct to the vector. Like, usually when I work with classes I would write like this
MyDummyClass m{1,2,3};
where as in Bjarne's example it is kinda given as(i.e. he just writes the struct name and then gives the values, without explicitly creating a Reading object if that makes sense..?)