C++ string类不能像C字符串能靠在i位赋值为‘\0’来截断
来源:互联网 发布:指南针软件是不是骗局 编辑:程序博客网 时间:2024/05/16 19:39
C++ string类不能像C字符串能靠在i位赋值为‘\0’来截断,因为'\0'在C字符串中才具有字符结束符的意义
#include <string>
#include <map>#include <iostream>
using namespace std;
int main()
{
string s("abcdefg");
s[3] = '\0';
cout << s.size() << endl;
cout << s.c_str() << endl;
char ss[10]={"abcdefg"};
ss[3] = '\0';
cout << ss << endl;
cout << string(ss) << endl;
return 0;
}
得结果为:
7
abcefg
abc
abc
abc
- C++ string类不能像C字符串能靠在i位赋值为‘\0’来截断
- c语言中赋值截断
- C+++string类如何判断字符串为空
- c 给字符串赋值
- string类和c字符串
- c 字符串与C++string
- c#-string 字符串相关
- [C++]string分割字符串
- C++_字符串(string)
- C#---字符串String
- C++string字符串1.1
- C#-String字符串操作
- C语言的位域赋值问题
- c语言 位域 赋值 问题
- 【c语言】位段赋值的例子
- string变量字符串的结束标志是什么,我看书上好像和c不一样,c的char *是以"\0"结束但c++好像不是
- 实现C++string的赋值函数
- 字符串处理总结之一(C#String类)
- POJ 2524 Ubiquitous Religions【并查集入门】
- 浅论网站优化还有涉足百度产品的必要吗
- 消息队列IPC(inter process communication)小记
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例) 和 IOS6屏幕旋转详解
- poj2593
- C++ string类不能像C字符串能靠在i位赋值为‘\0’来截断
- diff和patch命令在制作补丁时的使用方法
- Winpcap网络开发库入门
- Java中print、printf、println的区别
- 第五次课后作业
- Windows 7常用快捷键一览表
- 差点忘记编程是啥感觉
- 使用Scala编写Android程序
- Android ListView入门知识--各种Adapter配合使用