C++中两个string的比较

贴代码:

#include <iostream>
#include<string>
using namespace std;
void main()
{
    string str;
    cin>>str;
    if(str.compare("hello")==0)cout<<"succ"<<endl;
    else cout<<"wrong"<<endl;
}

体会:

网上搜索下,也许你都会知道一个函数strcmp,也许你正尝试着调试这个函数,但不幸的是这个函数的两个参数都必须是const。所以对于有一个参数必须由用户输入的情况,strcmp就显得无能为力,于是我们想到了C++的函数compare,可运行的代码如上。

原文地址:https://www.cnblogs.com/caixu/p/1997921.html