Hi all, this is my first post on the forum and I hope I can get some help with my problem.
I need to make a program to extract the last word from a sentence. I managed to extract the last character, but I have no idea how to get a word.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string strSentence = "Today will rain";
int intLength;
intLength = strSentence.length();
cout << "\nThe last character of " << strSentence
<< " is a " << "'" << strSentence.substr(intLength - 1,1) << "'" ;
cout << endl;
system("PAUSE");
return 0;
}//end main
Any help is appreciated!