I'm trying to make a function that takes the first and last letters of a string, divides them for the modulus and stores them in an array spot related to the modulus number. However I don't know how I would get the first and last letters of the string.
Asked
Active
Viewed 54 times
2 Answers
2
Assuming std::string str
, you can use either:
str.front()
andstr.back()
(C++11 and later only).str[0]
andstr[str.size()-1]
, ifstr
is not empty.

Remy Lebeau
- 555,201
- 31
- 458
- 770
1
You can have the first letter of your string by just using yourString[0]
and to get the last latter you can use yourString[yourString.size()-1]
EDIT
As said in the comments, assuming you're using std::string

Renan Klehm
- 158
- 1
- 1
- 9