#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 ++的新手,在我的基本计算机编程课上,我们必须制作可以计算音量的东西,有人可以帮我解决这个错误吗?
}
答案 0 :(得分:6)
您无法从cin
提取到endl
- 这没有任何意义。您将endl
与输出流一起使用以插入换行符并刷新流。只需删除>> endl
s。
此外,您拼错了length
。
答案 1 :(得分:0)
std::endl
用于输出流而不用于输入流。我认为如果它对初学者有意义,因为你可以把换行(并且大部分时间都必须在你想要从用户那里获取输入)到输入流中,但是std::endl
根本就没有不能使用std::cin
。
此外我相信你真的不需要这样做,因为当你按“Enter”键确认你的输入换行符也被打印到输出流。