在C++收到此错误,"std:cin.std 中的'运算符>>不匹配"

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

本文关键字:gt std 运算符 C++ 不匹配 中的 cin 错误      更新时间:2023-10-16
#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与输出流一起使用可以插入新行并刷新流。只需移除>> endls.

此外,您的length拼写错误。

std::endl用于输出流而非输入流。如果这对初学者来说有意义的话,我会反驳这一点,因为你可以将换行符(如果你想从用户那里获取输入,大多数时候都必须这样做)放入输入流中,但std::endl根本不适用于std::cin

此外,我相信您并不真的需要这样做,因为当您按下"Enter"键来确认您输入的换行符也被打印到输出流中时。