I think this is what you are looking for(for printing the last name alone)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string myString;
int i;
cout<<"\n Enter a name:";
getline(cin, myString, '\n');//Get a name where first name and last name is seperated by a space
i=myString.find(' ');//find the find occurance of space in that string
cout<<"thanks for shopping:";
cout<<myString.substr(i,myString.length());//printing the rest of the string from the occurence of space
return 0;
}
When you give input like 'Sachin Tendulkar' It says 'thanks for shopping:Tendulkar'