Print out the first letter of last letter

Beginner here. How would I print out the first letter of last name.

for example,

Last name: Khan

on the console, I want to print it out as "K" only.
Your title is a little confusing. But, if you have a sentence as your input, you could:

1
2
3
4
5
6
7

Read in the sentence

Start at the end of the sentence:
     Look at each character
     When the character is a space,
         You know the previous character is the character you want.


I hope this helps.
This will get you started
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// http://www.cplusplus.com/reference/string/string/erase/

#include <iostream>		// for cin, cout and cerr
#include <string>		// for the string datatype

using namespace std;	//

int main(int argc, char* argv[])
{

string myString="AnyName";
cout << myString << endl;  // Show string

cout << myString.size() << endl; // Show String Size
myString.erase (1,myString.size()); // Erase all but first char

cout << myString << endl; // Show result

return 0;
}
@fahmankhan75 Strings and cstrings( character arrays ) work the same. You can access the first element ( first letter ) by using the operator[] so you would call it like this mystring[0];
Thank you guys! :)
Topic archived. No new replies allowed.