在C ++中收到此错误,“与'operator>>不匹配"在'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;
我是C ++的新手,在我的基础计算机编程课程中,我们不得不做一些可以计算体积的事情,有人可以帮助我解决此错误吗?
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?
}
推荐答案
std :: endl
用于输出流,而不用于输入流.我认为这对初学者是否有意义,因为您可以将换行符(并且大多数情况下必须从用户那里获取输入)放入输入流,但是 std :: endl
根本不适用于 std :: cin
.
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
.
此外,我认为您并不需要这样做,因为当您按"Enter"键确认输入的换行符时,也将其打印到输出流中.
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.
这篇关于在C ++中收到此错误,“与'operator>>不匹配"在'std:cin.std中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!