且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将字符数组转换为字符串?

更新时间:2023-02-14 09:37:29

string 类有一个构造函数,它接受一个以 NULL 结尾的 C 字符串:

The string class has a constructor that takes a NULL-terminated C-string:

char arr[ ] = "This is a test";

string str(arr);


//  You can also assign directly to a string.
str = "This is another string";

// or
str = arr;