【问题标题】:Getting this error in C++, "no match for 'operator>>' in 'std:cin.std在 C++ 中出现此错误,“'std:cin.std 中的 'operator>>' 不匹配”
【发布时间】:2014-02-27 22:06:59
【问题描述】:
#include <iostream>

int main()
{
    using std::cout;
    using std::endl;
    using std::cin;
    short width;
    short legnth;
    short height;
    short volume;
    volume = (legnth * width * height);

    cout << "This program will determine the volume of a cube" << endl;
    cout << "Enter the legnth of the cube: ";
    cin >> legnth >> endl;
    cout << "Enter the width of the cube: ";
    cin >> width >> endl;
    cout << "Enter the height of the cube: ";
    cout << "Your volume is: " << volume;
    cout << "Press any key to exit :)";
    cin.get();

    return 0;

我是 C++ 新手,在我的基本计算机编程课程中,我们必须做一些可以计算体积的东西,有人可以帮我解决这个错误吗?

}

【问题讨论】:

    标签: c++


    【解决方案1】:

    您不能从 cin 提取到 endl - 这没有任何意义。您将endl 与输出流一起使用以插入换行符并刷新流。只需删除&gt;&gt; endls。

    另外,你拼错了length

    【讨论】:

      【解决方案2】:

      std::endl 用于输出流而不是输入流。如果这对初学者有意义,我会提出异议,因为您可以将换行符(如果您想从用户那里获取输入,大多数情况下必须这样做)到输入流中,但 std::endl 根本没有与std::cin 合作。

      此外,我相信您实际上并不需要这样做,因为当您按“Enter”键确认您输入的换行符也被打印到输出流时。

      【讨论】:

      • 谢谢!!我的教授对我来说移动得太快了!在他让我们做的所有练习题都搞砸了 2 个小时之后,我终于对他所涵盖的所有材料有了一个大概的了解,但我只是被一个错误难住了!我敢肯定,如果教授真的按时间顺序高效地教学,我会知道 std::cin 是如何工作的,但不幸的是,生活并不总是如你所愿,哈哈。
      猜你喜欢
      • 2014-05-16
      • 2011-12-10
      • 2013-07-31
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多