I want to confirm if the "break;" line exit the if-statement or the while loop.
which one is correct?
The break statement exits the 'most current' loop block. In your example, that is the while loop.
if there are more while loop outside the while loop written above, which does the break; line refer to?
The break statement will exit the innermost loop. For example:
- while (condition1) {
-
while (condition2) {
-
if (condition3) {
-
cout << "If statement." << endl;
-
break;
-
}
-
cout << "End of loop2." << endl;
-
}
-
cout << "End of loop1." << endl;
-
}
In this code, if the break statement is reached, "End of loop2" will not print, because the rest of the body of the second loop is skipped. But the first loop is not affected, and prints "End of loop1." before continuing (if condition1 is true, of course).
are there any other ways that i can use ispunct function for string type data?
You can actually just say:
The STL string class has overloaded the square bracket operators to return the character at the specified position, as if it were a character array.