目标是编写一个简单的程序,读取两个字符串并相互比较。错误(C2679二进制'>>')指向代码的输入行,'cin'行。我已经完成了#include和using声明,但也许我遗漏了一个对我来说不明显的符号:
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main(){
// define two strings
string s1, s2;
// read two strings
cin >> s1 >> s2 >> endl;
// compare two strings to determine if equal or report the larger
if(s1 != s2){
if(word1 > word2)
cout << s1 << " is larger than " << s2 << endl;
else
cout << s2 << " is larger than " << s1 << endl;
} else
cout << "The words are equal in size" << endl;
return 0;
}
提前感谢!
- 使用
endl
和cin
是没有意义的。>> endl
应移除 word1
和word2
没有在这里声明。看起来if(word1 > word2)
应该是if(s1 > s2)
。