You can get a specific character from a string simply by indexing it. For example, the fifth character of str
is str[4]
(off by one since the first character is str[0]
).
Keep in mind you'll run into problems if the string is shorter than your index thinks it is.
c_str()
, as you have in your comments, gives you a char*
representation (the whole string as a C "string", more correctly a pointer to the first character) rather than a char
.
You could equally index that but there's no point in this particular case.