while using std::cin >> number in the following way:
float number;
while(std::cin >> number) {
//perform a check here if possible
//if number does not contain a decimal point do this
for(int i = 0; i < number; i++) {
std::cin >> readMoreFloats;
}
//otherwise read 1000 more floats
}
is there a way to be able to distinguish between the following types of lines:
1.500 (1000 more floats)
2 2.000 2.000
The lines will either begin with a float or an int. If the lines begin with a float I want to read 1000 more floats. If it is an int, I want to read that number of floats. I know I could cast the float to an int and check if the casted int is equal to the float, but that would not work when a float has a flat value such as 1.000.
I'd prefer to not read the entire line using getline() because splitting it afterwords is time consuming, and I already know that all of the input are floats except for possibly the first number. Another way would be to read in the first value of each line as a string and check to see if it contains a period. Is there a way, without first reading the input as a string, to check for this? Or is the string step required.