I have a text file like this :
Sting Another string 0 12 0 5 3 8
Sting Another string 8 13 2 0 6 11
And I want to count how many numbers are there. I think my best bet is to use while type cycle with a condition to end counting then another line starts but I do not know how to stop reading at the end of a line.
Thanks for your help in advance 😉
Split your
inputstream into linesTo split a line into words, use a stringstream:
You can repeat this for each word to decide whether it contains a number. Since you didn’t specify whether your numbers are integer or non-integers, I assume
int:Disclaimer: This approach is not perfect. It will detect “numbers” at the beginning of words like
123abc, it will also allow an input format likestring 123 string. Also this approach is not very efficient.