注册 登录
编程论坛 C++教室

求指点错误

cactusj 发布于 2012-12-13 15:05, 210 次点击
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
    string s1="Zhaojunn",s2="Zhaojun";
   cin>>s1>>endl;
   cin>>s2>>endl;
   if(s1==s2)
       cout<<"s1=s2!!"<<endl;
   else
       if(s1>s2)
           cout<<"s1>s2!!"<<endl;
       else
           cout<<"s1<s2!!!"<<endl;

   return 0;
}


错误是:d:\vc++\day1\ex3_7\ex3_7.cpp(10) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
求高手指点~~~不胜感激!!
2 回复
#2
wp2319572012-12-13 15:11
#include<iostream>
#include<string>
using namespace std;
int main()
{
   string s1,s2;
   cin>>s1;
   cin>>s2;
   if(s1==s2)
       cout<<"s1=s2!!"<<endl;
   else
       if(s1>s2)
           cout<<"s1>s2!!"<<endl;
       else
           cout<<"s1<s2!!!"<<endl;

   return 0;
}
#3
crystall2012-12-13 15:16
程序代码:
#include "stdafx.h"

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

int main()
{
    string s1 = "Zhaojun", s2="Zhaojun";

    cout << "请输入字符串1: ";
    cin >> s1;

    cout << "请输入字符串2: ";
    cin >> s2;

   if(s1==s2)
   {
       cout<< "s1 == s2" <<endl;
   }
   else
   {
       if(s1>s2)
           cout << "s1 > s2" << endl;
       else
           cout << "s1 < s2" << endl;
   }

   return 0;
}
1