简体   繁体   中英

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?

}

You can't extract from cin to endl - that doesn't make any sense. You use endl with output streams to insert a newline and flush the stream. Just remove the >> endl s.

Also, you've spelled length incorrectly.

std::endl is used for output stream not for input stream. 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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