Look at the code here:
if (pos != -1)
{
goto badsearch;
}
I think you meant:
if (pos == -1)
{
goto badsearch;
}
Another thing is that string::search() returns string::npos if the search function does not find what it was told to find, and not -1, so the code should be:
if (pos == string::npos)
{
goto badsearch;
}
cout << search;
pos = search.find("=");
if (pos != string::npos)
{
cout << "\n" << pos;
}
And one last thing: you can avoid using goto
in your 'if' statement by replacing it with the statement continue;
- this will jump to the beginning of the while loop:
if (pos == string::npos)
{
continue;
}