示例示例将char转换为string可以使用C++标准库中的string类的构造函数,如下所示:输出:
将char转换为string可以使用C++标准库中的string类的构造函数,如下所示:
cpp
#include
#include
int main()
{
char c = 'a';
std::string s(1, c); // 构造函数:string(size_type count, char ch)
std::cout << s << std::endl;
return 0;
}
输出:
a
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(82条)