I found this useful:
In this lab, we are performing different functions based on a naming scheme we read in. But the names we read in have extra characters on the end. Example: VIP7 is a vip, but how do we extract the ‘VIP’ part of the name to know he’s a VIP.
One easy way to do this is to use the string ‘find’ method.
Find Format:
size_type find( const string& str, size_type index );
where ‘str’ is what you are searching for, and ‘index’ is where you start.
This returns a number of type string::size_type representing the location where this ‘str’ string starts. But if this search string is not found, then, the method returns a string::npos.
So we can use this find method to check for “VIP” or “Customer” in the name, and take the appropriate action.
string::size_type vip_location = patronName.find( "VIP", 0 );
if(vip_location != string::npos)
We also need to check the VIP’s number value to see if the next VIP should be added to the stack. We can use the at and length methods of string to get at the last value in the string:
char num = name.at(name.length()-1);