char to string

closed account (jwkNwA7f)
How can I convert a char to string?

Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include <sstream>

std::string cha2str(char ch){
    std::stringstream ss;
    std::string s;
    ss << ch;
    ss >> s;
    return s;
}

int main(){
    char c = 'a';
    std::cout << cha2str(c) << std::endl;
}
Last edited on
char c = 'A';

std::string s( 1, c );
thats the basic
1
2
3
char a;
a=cin.get();
stringname.push_back(a);
Last edited on
closed account (jwkNwA7f)
Thank you!
Topic archived. No new replies allowed.