简体   繁体   English

在C ++中遇到此错误,“ std:cin.std”中的“操作符>>不匹配”

[英]Getting this error in C++, "no match for 'operator>>' in 'std:cin.std

#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;

I am new to C++ and in my basic computer programming class we had to make something that can calculate volume, can someone please help me in fixing this error? 我是C ++的新手,在我的基本计算机编程课程中,我们不得不做一些可以计算体积的事情,有人可以帮助我解决此错误吗?

} }

You can't extract from cin to endl - that doesn't make any sense. 您无法从cin提取到endl这没有任何意义。 You use endl with output streams to insert a newline and flush the stream. endl与输出流一起使用以插入换行符并刷新流。 Just remove the >> endl s. 只需删除>> endl

Also, you've spelled length incorrectly. 另外,您拼写的length不正确。

std::endl is used for output stream not for input stream. std::endl用于输出流,而不用于输入流。 I'd argue with that if it makes sense to a beginner, because you can put newline (and most of the time have to if you want to grab input from the user) into the input stream, but std::endl simply doesn't work with std::cin . 我认为这对初学者是否有意义,因为您可以将换行符(并且大多数情况下必须从用户那里获取输入)放入输入流中,但std::endl根本不会这样做”与std::cin

Besides I believe you don't really need to do it, because when you press "Enter" key to confirm your input newline character is also being printed to output stream. 此外,我相信您并不需要这样做,因为当您按“ Enter”键确认输入的换行符时,也会将其打印到输出流中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM