Finding number in string

This is a discussion on Finding number in string within the C++ Programming forums, part of the General Programming Boards category; Would there be an easier way to find and print out one number from a string without knowing the number?
...

Is it possible that by "without knowing the number" you really mean "with the number in a variable"? If so, there are such things as loops, for when you want to repeat something a certain number of times.

If it's always the fifth number (== after the fourth comma) then I'm not sure you have a question, since that's what you started with.

Anyway, as a suggestion, because I've been in a stringstream frame of mind for the last little while, why not use a stringstream? You can initialize your stringstream with the string you've got, and peel off numbers with >> until you get to the one you want. (You'll either have to read the comma, or there's probably some magic you can do to make >> think (at least temporarily) that comma is a whitespace character so it will automatically separate and be removed.)

(You'll either have to read the comma, or there's probably some magic you can do to make >> think (at least temporarily) that comma is a whitespace character so it will automatically separate and be removed.)