1 //method 1: the constructor of string() 2 char c = ‘F‘; 3 string s = string(1, c); 4 cout << s ;
1 //method 2: stringstream 2 char c1 = ‘F‘; 3 stringstream ss; 4 ss << c1; 5 string s2; 6 ss >> s2; 7 cout << s2;
1 //method 3: sprintf() 2 char c2 = ‘F‘; 3 char s3[] ={}; 4 sprintf(s3, "%c", c2); 5 string s4 = string(s3); 6 cout << s4;
水滴石穿,笨鸟先飞!
原文:https://www.cnblogs.com/sheepcore/p/12376856.html