#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s="123456789";//定义字符串
//    cin>>s;//输入
//    getline(cin,s);//输入整行,不包括换行
//    cout<<s.length()<<endl;//输出字符串长度
//    s=s+"123"; //字符串拼接
    //s.append("123");//字符串末尾添加字符串
    //s.push_back('1');//字符串末尾添加字符
    cout<<s<<endl;//输出
    
//    for(int i=0;i<s.length();i++){//操作字符
//        cout<<s[i]<<endl;
//    }
    
    //for(int i=0;s[i]!='\0';i++){//错误,string不以'\0'结尾
    //    cout<<s[i]<<endl;
    //}
    
    //查找
//    cout<<s.find('2')<<endl;
//    cout<<s.find('2',2)<<endl;
//    cout<<s.find("12")<<endl;
//    cout<<s.find("12",2)<<endl;
    
//    s.insert(2,"456");//插入数据
//    cout<<s<<endl;
    
    //截取
//    cout<<s.substr(2)<<endl;
//    cout<<s.substr(2,3)<<endl;
    
    //转c语言字符数组
//    const char *c = s.c_str();
//    cout<<c<<endl;
    
    //字符串比较
//    string str1="123",str2="456789";
//    if(str1.compare(str2)>0)
//        printf("str1>str2\n");
//    else if(str1.compare(str2)<0)
//        printf("str1<str2\n");
//    else
//        printf("str1==str2\n");
    
    return 0;
}

发表评论