std::string 用法

例子:

#include <iostream>
#include <string>

using namespace std;
int main(){
   
    string strinfo="Alis";

    if( strinfo == "winter" )
        cout << "you are winter!"<<endl;
    else if( strinfo != "wende" )
        cout << "you are not wende!"<<endl;
    else if( strinfo < "winter")
        cout << "your name should be ahead of winter"<<endl;
    else
        cout << "your name should be after of winter"<<endl;

    cout << strinfo + " Welcome to China!"<<endl;
    cout <<"Your name is :"<<endl;
    string strtmp = "How are you? " + strinfo;
    for(int i = 0 ; i < strtmp.size(); i ++)
        cout<<strtmp[i];

    return 0;
}

输出:

you are not wende!
Alis Welcome to China!
Your name is :
How are you? Alis
全部评论

相关推荐

2025-12-30 14:09
已编辑
北京交通大学 算法工程师
字节跳动 训练框架研发 (N+2) * (12 + 3) 硕士211
Crinton:训练框架遥遥领先
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务