std::string字符串中间存放‘‘

Posted 赤龙绕月

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了std::string字符串中间存放‘‘相关的知识,希望对你有一定的参考价值。

std::string字符串是以’\\0’结尾的,哪怎么在字符串中间存放’\\0’呢

char sz1[4] =  'A','\\0','B','\\0' ;
std::string str1(sz1);
std::string str2(sz1, 4);
std::string str3;
str3.assign(sz1, 4);

std::cout << sz1 << std::endl;
std::cout << str1 << std::endl;
std::cout << str2 << std::endl;
std::cout << str3 << std::endl;

str2与str3

输出结果为

A
A
AB
AB

以上是关于std::string字符串中间存放‘‘的主要内容,如果未能解决你的问题,请参考以下文章