This is a mistake (and uses an unitialized variable):
while (stringPos < 1);
as it is equivalent to:
while (stringPos < 1) {}
If this did not enter an infinite loop the code following it would be executed once only. To correct:
- Initialize the variables
stringPos
andfound1
. - Use type
size_t
forstringPos
andfound
asstd::string::find()
does not return anint
, but returnssize_type
(usuallysize_t
). - Use
std::string::npos
instead of-1
to test for not found. - Remove the trailing semi-colon.