/*string的构造函数
*/
/*
#include<iostream>
using namespace std;
#include<string>
int main()
{
string a(4,'c');
string b("value");
string c(b);
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
//判断字符串是否为空
if(!c.empty())
{
cout<<"c is not empty"<<endl;
// string::size_type=c.size();
// cout<<string::size_type<<endl;
}
//按照字符下标输出字符串
cout<<c[4]<<endl;
//字符串重载+号操作符
c+=c;
//字符串重载=操作符
a=c;
if(a==c)
{
cout<<"a is equal to c"<<endl;
}
cout<<a<<endl;
cout<<c<<endl;
string d;
//输出带空格的字符串的方法
getline(cin,d);
cout<<d<<endl;
//输出带空格后面的字符串的方法
string e;
while(cin>>e)
{
cout<<e;
}
return 0;
}
*/
/*字符串的赋值
*/
#include<iostream>
using namespace std;
#include<string>
int main()
{
string s1="asdf";
string s2="sefwe";
string s3=s1+s2;
string s4="asdfe"+s3;
cout<<s4<<endl;
cout<<s3<<endl;
string::size_type si;
for(si=0;si<s4.size();si++)
cout<<s4[si]<<endl;
if(isalnum(s4[4]))
{
cout<<"yes"<<endl;
}
if(isdigit(s4[4]))
{
cout<<"is digital"<<endl;
}
if(isupper(s4[4]))
{
cout<<"is upper alpher"<<endl;
}
for(si=0;si!=s4.size();si++)
{
s4[si]=toupper(s4[si]);
}
cout<<s4<<endl;
return 0;
}
string类型操作
最新推荐文章于 2022-11-15 16:47:18 发布