string char* '\0' "\0"
2012-07-13 14:01
316 查看
在给string char*赋完之后,如果把其中的某一位变为'\0',输出该字符串的时候,该位后面的字符依然能显示出来。
往string中添加‘\0'时,string的长度增加,但添加字符串“\0”时,string长度不增加。
#include <iostream>
#include<string>
using namespace std;
int main()
{
int i;
char* c="abcde";
string str=c;
cout<<"str:"<<str<<endl;
str[2]='\0';
str+='\0';
str+='\0';
str+='\0';
str+='\0';
str+='\0';
str+="\0";
str+='\0';
str+='\0';
str+='\0';
str+="\0";
str+="\0";
str+="\0";
str+="\0";
cout<<"str:"<<str<<endl;
cout<<"str.length:"<<str.length()<<endl;
return 0;
}
往string中添加‘\0'时,string的长度增加,但添加字符串“\0”时,string长度不增加。
#include <iostream>
#include<string>
using namespace std;
int main()
{
int i;
char* c="abcde";
string str=c;
cout<<"str:"<<str<<endl;
str[2]='\0';
str+='\0';
str+='\0';
str+='\0';
str+='\0';
str+='\0';
str+="\0";
str+='\0';
str+='\0';
str+='\0';
str+="\0";
str+="\0";
str+="\0";
str+="\0";
cout<<"str:"<<str<<endl;
cout<<"str.length:"<<str.length()<<endl;
return 0;
}
相关文章推荐
- C语言关于"0" '0' '\0'之间的区别。
- TabIndex 属性 Tabindex="-1" 与Tabindex="0"、任意数字
- Longest Subarray with Equal "1" and "0"
- Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
- Exception in thread "Thread-0" java.lang.IllegalMonitorStateException
- Exception in thread "Thread-0" org.eclipse.swt.SWTException: Invalid thread access. 错误解决
- Weblogic 10 BEA-000627 &amp;amp;gt;&amp;amp;gt; Reached maximum capacity of pool "My Connection Pool", making "0" new resource
- php小结---当解析变量的值分别为 null, "" ,0 ,"0" ,1 时的不同情况
- Win7下运行小雨伞tinyumbrella-5/6异常:Exception in thread "AWT-EventQueue-0"解决办法
- 解决ADT大量出现"Unexpected value from nativeGetEnabledTags: 0"的问题
- 曾经安装过MySQL数据库,已卸载,但仍无法重新安装MySQL,提示错误"Cannot create windows service for mysql.error:0"
- Mysql "Cannot create windows service for mysql.error:0" 安装删...
- Oracle EBS 报表输出字符字段前部"0"被Excel自动去掉问题
- 关于java的Graphics出现“Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.”
- 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC" task.
- hive 函数参数产生的错误:Hive Runtime Error while processing row {"sys":"0"}
- 如何解决在快速向jtable添加数据的时候报AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:异常
- oracle保存小数点前为"0"的问题
- days.add("0"+i);
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException