Here's a simple example of their use. The exercise is left for you to implement back into your program.
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
std::string Data = "Hi there, my name is Todd, what's yours?" ;
// To find the last occurence of a character, use rfind()
// When using string.rfind(), it returns a data type of "string::size_type"
string::size_type pos = Data.rfind(',') ; // return the position of the rightmost comma
if (pos == string::npos) {
cout << "Comma not found!! Data format error" << endl ;
return -1 ;
}
// Otherwise, write out the final substring of Data starting after "pos"
cout << (Data.substr(pos+1)) << endl ;
return 0;
}
Todd