#include <iostream>
#include<cctype>
using std::cout;
using std::cin; using std::string;
int main()
{
string name;
getline(cin, name);
string first_name(name.size(), ' ');
//to get the first name
for (string::size_type i=0; i!=name.size(); ++i)
{
if (isspace(name[i])) //will check if "i" char of name is space, if yes then break and out of the loop.
break;
first_name[i]= name[i];
}
int ch_cnt=0;
//to get the no. of char in first name
for (string::size_type i=0; i!=first_name.size(); ++i)
{
if (isalnum(first_name[i]))
++ch_cnt;
}
first_name.erase(ch_cnt, first_name.size()); // remove the unnecessary spaces form first name
cout <<first_name <<" " << "How are you?";
return 0;
}
So we can get last name also in a string and print it.