C++之string
来源:互联网 发布:如何查看淘宝联盟pid 编辑:程序博客网 时间:2024/05/16 14:33
在C++中我们用string来代替在C语言中char类型很多单操作的繁琐。
初始化string对象的方式:
string的常用操作:
注意:
string str="Hello"+"World"//双引号引起的字符串通过加号链接是非法的
下面以一段代码来体会一下string的快感
/*题目描述: 1.提示用户输入姓名 2.接收用户的输入 3.然后向用户问好,hello xxx 4.告诉用户名字的长度 5.告诉用户名字的首字母 6.如果用户直接输入回车,那么告诉用户的输入为空 7.如果用户输入的是imooc,则告诉用户是一个管理员*/#include<iostream>#include<string>using namespace std;int main(){ string name; cout << "Please input your name" << endl; getline(cin, name);//如果直接用cin,那么回车会被保存,getline能将输入储存在name中 if (name.empty()) { cout << "input is null.." << endl; system("pause"); return 0; } if (name=="imooc") { cout << "You are a adminitrator" << endl; } cout << "hello" + name << endl; cout << "your name length is" <<name.size() << endl; cout << "your name first letter is" << name[0] << endl; system("pause"); return 0;}
0 0
- C++STL之string
- C++STL之string
- C++STL之string
- C++STL之string
- c++primer之string
- c++STL之string
- C++STL之string
- C++STL之string
- C++STL之string
- C++STL之string
- C++STL之string
- C++STL之string
- 【C++】C++之string
- C++STL之string
- C++STL之string
- c++stl之string
- C++STL之string上
- C++STL之string下
- jwplayer 禁止视频的快进,但是可以后退(已实现)
- mac上利用tomcat安装jenkins
- 设计模式笔记十四:责任链模式
- 如何仅用递归函数和栈操作逆序一个栈
- BZOJ1649: [Usaco2006 Dec]Cow Roller Coaster
- C++之string
- 蓝桥杯寒假任务之关联矩阵
- bootstrap icheck插件分享
- Phonegap调用摄像头出错
- java spring为ApplicationContext提供有三种实现(dubbo-consumer.xml)
- LeetCode 215. Kth Largest Element in an Array
- oracle中实现自增id
- 深度神经网络(DNN)的正则化
- code 10-2 中KMeans函数PAD图