C++ 定义string类型变量
2014-02-24 12:35
295 查看
#include<iostream> #include<string> using namespace std; int main() { string s1;//s1为空串 /* s1 = "aaa"; string s2(s1); //s2复制s1 if(s2 == s1){ cout<<"string s2(s1): s2 = s1"<<endl; } s1 = "begin"; cout<<s2<<endl; s1 = "change"; cout<<s2<<endl;*/ s1 = "aaa"; string s2 = s1; if(s2 == s1){ cout<<"string s2=s1: s2 = s1"<<endl; } s1 = "begin"; cout<<s2<<endl; s1 = "change"; cout<<s2<<endl; // string s3("value"); string s3="value"; string s4(10, 'c');//将s4初始化为10个字符‘c’ cout<<s3<<endl<<s4<<endl; return 0; }
相关文章推荐
- c语言结构体的偏移、c++
- 几个不安全的c语言库函数
- EAST_ZJU_PAT_DAVANCED LEVEL_1035 利用面向对象,化简分析过程
- C++ 类里面,函数占用存储空间问题
- EASY_ZJU_PAT ADVANCED LEVEL_1031 仔细分析,删繁就简
- c语言内存分配方式
- c语言结构体用法
- effective C++
- 查找最小的k个元素 C++实现
- 我的vc++6.0编译的时候没有问题,运行的时候为什么总是报告一个错误?
- 2013华为机试字符串压缩
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换
- C语言函数申明关键字inline
- hdoj1020--Encoding
- C++函数高级特征
- C,C++基础和编程风格(2)
- C,C++基础和编程风格(1)
- 深入理解C语言-----各数据类型大小
- 常问的CC++基础题
- hdu 2047