user3179985
user3179985

Reputation: 93

C++ - Convert String to Char

I was wondering if there is a way to convert from a string object into a char. For example:

string str = "b";
char ch = //convert str to char

Any help would be appreciated. Thanks.

Upvotes: 0

Views: 288

Answers (1)

HadeS
HadeS

Reputation: 2038

You can directly index the string to get the character you want in a same way you index simple arrays.

char ch = str[0];

This will work for you..

Upvotes: 1

Related Questions