错误:与';不匹配;运营商>&燃气轮机';在';标准:cin>&燃气轮机;中途停留'; 我试图回到C++中,这是我的第二个程序。一切都编译得很好,直到它停下来返回似乎相当常见的错误:错误:与“std::cin>>stopat”中的“operator>>”不匹配 我已经看了一些东西来解释是什么导致了这种情况,但实际上我什么都不懂(因为我在编程方面相对缺乏经验)。是什么导致了这个错误,如果我再次遇到它,我该如何修复它 #include <iostream> #include "BigInteger.hh" using namespace std; int main() { BigInteger A = 0; BigInteger B = 1; BigInteger C = 1; BigInteger D = 1; BigInteger stop = 1; cout << "How Many steps? "; BigInteger stopat = 0; while (stop != stopat) { if (stopat == 0) { cin >> stopat; cout << endl << "1" << endl; } D = C; C = A + B; cout << C << endl; A = C; B = D; stop = stop + 1; } cin.get(); } #包括 #包括“biginger.hh” 使用名称空间std; int main() { 大整数A=0; 大整数B=1; 大整数C=1; 大整数D=1; BigInteger停止=1; 停车; cout

错误:与';不匹配;运营商>&燃气轮机';在';标准:cin>&燃气轮机;中途停留'; 我试图回到C++中,这是我的第二个程序。一切都编译得很好,直到它停下来返回似乎相当常见的错误:错误:与“std::cin>>stopat”中的“operator>>”不匹配 我已经看了一些东西来解释是什么导致了这种情况,但实际上我什么都不懂(因为我在编程方面相对缺乏经验)。是什么导致了这个错误,如果我再次遇到它,我该如何修复它 #include <iostream> #include "BigInteger.hh" using namespace std; int main() { BigInteger A = 0; BigInteger B = 1; BigInteger C = 1; BigInteger D = 1; BigInteger stop = 1; cout << "How Many steps? "; BigInteger stopat = 0; while (stop != stopat) { if (stopat == 0) { cin >> stopat; cout << endl << "1" << endl; } D = C; C = A + B; cout << C << endl; A = C; B = D; stop = stop + 1; } cin.get(); } #包括 #包括“biginger.hh” 使用名称空间std; int main() { 大整数A=0; 大整数B=1; 大整数C=1; 大整数D=1; BigInteger停止=1; 停车; cout,c++,operators,no-match,C++,Operators,No Match,您尚未向我们展示BigInteger的代码,但需要定义一个函数(在BigInteger.hh或您自己的代码中),如下所示: std::istream& operator >>(std::istream&, BigInteger&); std::istream& operator >>(std::istream& stream, BigInteger& value) { std::string word; i

您尚未向我们展示BigInteger的代码,但需要定义一个函数(在BigInteger.hh或您自己的代码中),如下所示:

std::istream& operator >>(std::istream&, BigInteger&);
std::istream& operator >>(std::istream& stream, BigInteger& value)
{
    std::string word;
    if (stream >> word)
        value = BigInteger(word);
}
std::istream &operator>>(std::istream &is, BigInteger &bigint)
{ 
    // parse your bigint representation there
    return is;
}
需要实现此函数才能从流中实际获取“单词”,并尝试将其转换为BigInteger。如果幸运的话,BigInteger将有一个接受字符串的构造函数,在这种情况下,它将如下所示:

std::istream& operator >>(std::istream&, BigInteger&);
std::istream& operator >>(std::istream& stream, BigInteger& value)
{
    std::string word;
    if (stream >> word)
        value = BigInteger(word);
}
std::istream &operator>>(std::istream &is, BigInteger &bigint)
{ 
    // parse your bigint representation there
    return is;
}
编辑:现在您已经指出了正在使用的库,下面是您可以做的。库本身可能应该为您这样做,因为它提供了相应的ostream操作符,但是如果您深入研究,您会发现通用的、库质量的流操作符比我写的更复杂g在这里

#include <BigIntegerUtils.hh>

std::istream& operator >>(std::istream& stream, BigInteger& value)
{
    std::string word;
    if (stream >> word)
        value = stringToBigInteger(word);
}
#包括
std::istream和运算符>>(std::istream和stream、BigInteger和value)
{
字符串字;
如果(流>>word)
值=StringToBiginger(字);
}

这里遗漏的是关于
biginger
类的详细信息。为了使用
>
运算符从输入流中读取一个,您需要为类定义
运算符>>
(通常称为流提取器)。这就是您遇到的编译器错误的含义

本质上,您需要的是一个如下所示的函数:

std::istream& operator >>(std::istream&, BigInteger&);
std::istream& operator >>(std::istream& stream, BigInteger& value)
{
    std::string word;
    if (stream >> word)
        value = BigInteger(word);
}
std::istream &operator>>(std::istream &is, BigInteger &bigint)
{ 
    // parse your bigint representation there
    return is;
}

什么是
biginger
?似乎它没有
>
运算符。什么是biginger?如果它是类的名称,那么肯定没有重载运算符>>。
value=biginger(word)
可能涉及一个不必要的副本,因为
biginger
类肯定有一个成员函数来解析字符串中的数字(如果它提供这样的构造函数,至少是有意义的).因为我写了我的答案,OP贴出了一个链接到有问题的实际图书馆,所以现在我们可以确定。我会相应地更新我的答案。