我在学习C++并尝试了一些东西......以下代码给了我一个编译时错误,任何人都可以向我解释为什么,我有点困惑......我是假设它是cin >> playagain
声明。感谢您的帮助。 (另外,如果我做任何其他的一般的C++错误,请让我知道)C++编译时错误
继承人的错误:
错误1错误C2679:二进制“>>”:没有运营商发现,这需要右手操作数'std :: string'(或没有可接受的转换)c:\ users \ abdo \ documents \ visual studio 2012 \ projects \ consoleapplication1 \ consoleapplication1 \ consoleapplication1.cpp 45 1 ConsoleApplication1
反正,包括#include <string>
修复了这个问题,谢谢0x499602D2
#include "stdafx.h"
#include <iostream>
using namespace std;
class calculatorc1 {
public:
calculatorc1();
~calculatorc1();
int multnums(int a, int b);
protected:
int result;
};
calculatorc1::calculatorc1() {
}
calculatorc1::~calculatorc1() {
}
int calculatorc1::multnums(int a, int b) {
int result = a * b;
return result;
}
int main()
{
string playagain;
bool calcing = true;
while (calcing) {
calculatorc1 c;
int x;
int y;
cout << "first num\n";
cin >> x;
cout << "second\n";
cin >> y;
cout << c.multnums(x, y) << "\n";
cout << "mul again? (y/n)\n";
cin >> playagain;
if (playagain == "n") {
calcing = false;
system("pause");
}
}
}
认真吗?你不会告诉我们错误是什么?你期望我们猜测? – John3136
什么是错误? – 0x499602D2
为什么我看到如此多的问题“这段代码给出了一个错误”而没有指定错误?人们如何认为这与问题的具体错误无关? – Jack