Convert a single character to a string?
Off the top of my head, if you're using STL then do this:
string firstLetter(1,str[0]);
You can use the std::string(size_t , char )
constructor:
string firstletter( 1, str[0]);
or you could use string::substr()
:
string firstletter2( str.substr(0, 1));
1) Using std::stringstream
std::string str="abc",r;
std::stringstream s;
s<<str[0];
s>>r;
std::cout<<r;
2) Using string ( size_t n, char c );
constructor
std::string str="abc";
string r(1, str[0]);
3) Using substr()
string r(str.substr(0, 1));
string s;
char a='c';
s+=a; //now s is "c"
or
char a='c';
string s(1, a); //now s is "c"