I have a C++ programming problem to extract a suffix such as Jr. or Sr. from a string that may vary each time. We are currently working with one assigned variable but I wanted to know how to code it if I have a file that would vary instead of working with a constant variable. I have the program working for the constant but I would like to know how to code for a file. The Proff. said we would have to look for the space but we would have to extract the previous spaces first???? Here is what I have:
Code:
#include <iostream> #include <string> using namespace std; //extracts data from string int main() { string fullName = "Mike Lee Stephen, Jr"; string fname, mname, lname, suffix; string position; position = fullName.substr(17,2); //*lname = fullName.substr(position, 8); cout << position << endl; return 0; }
Comment