C++之string的用法练习实例
1.题目如下:

2.代码分享如下:
include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
string name;
cout << "please input your name:" << endl;
getline(cin,name);
if(name.empty())
{
cout << "input is null..." << endl;
system("pause");
return 0;
}
if(name == "imooc")
{
cout << "you are a administrator" << 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;
}
3.测试结果:
输入xiaoguan

输入imooc

输入回车

到这程序算是成功运行了
希望能帮到大家,问你们要一个赞,你们会给吗,谢谢大家
版权声明:本文版权归作者(@攻城狮小关)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
大家写文都不容易,请尊重劳动成果~
交流加Q:1909561302
CSDN地址https://blog.csdn.net/Mumaren6/


浙公网安备 33010602011771号