user3362546
user3362546

Reputation: 65

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?

}

Upvotes: 0

Views: 34226

Answers (2)

Peter Nimroot
Peter Nimroot

Reputation: 545

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.

Upvotes: 1

Joseph Mansfield
Joseph Mansfield

Reputation: 110748

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 >> endls.

Also, you've spelled length incorrectly.

Upvotes: 6

Related Questions