[英]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 ++的新手,在我的基本计算机编程课程中,我们不得不做一些可以计算体积的事情,有人可以帮助我解决此错误吗?
}
您无法从cin
提取到endl
这没有任何意义。 将endl
与输出流一起使用以插入换行符并刷新流。 只需删除>> endl
。
另外,您拼写的length
不正确。
std::endl
用于输出流,而不用于输入流。 我认为这对初学者是否有意义,因为您可以将换行符(并且大多数情况下必须从用户那里获取输入)放入输入流中,但std::endl
根本不会这样做”与std::cin
。
此外,我相信您并不需要这样做,因为当您按“ Enter”键确认输入的换行符时,也会将其打印到输出流中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.