码迷,mamicode.com
首页 > 其他好文 > 详细

string 训练

时间:2017-03-30 12:58:42      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:code   lease   end   bsp   管理   cout   out   empty   nbsp   

#include<iostream>
#include<string>
using namespace std;

int main()
{
//
 string s1="please input your name";
 string s2="";
 string s3=s1+s2;
 //string s5="a"+"b";不允许这样定义!!!至少有有变量
 cout<<s3<<endl;
  string name;
 getline(cin,name);
 if(name.empty())
      cout<<"名字不能为空"<<endl;
 else
   cout<<"hello! "<<name<<endl;
    if(name=="imooc")
   cout<<"你是管理员"<<endl;
  cout<<"你的名字长度是:"<<name.size()<<endl;//不包括‘\0‘
  cout<<"你的名字的第一个字母是"<<name[0]<<endl;
}

 

string 训练

标签:code   lease   end   bsp   管理   cout   out   empty   nbsp   

原文地址:http://www.cnblogs.com/cxy931980808/p/6645550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!