1. 使用string()构造函数方法
1 //method 1: the constructor of string()
2 char c = 'F';
3 string s = string(1, c);
4 cout << s ;
2. 使用stringstream字符流
1 //method 2: stringstream
2 char c1 = 'F';
3 stringstream ss;
4 ss << c1;
5 string s2;
6 ss >> s2;
7 cout << s2;
3. 使用springf()函数
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
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/193712
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!