在C++收到此错误,"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++的新手,在我的计算机编程基础课上,我们必须制作一些可以计算音量的东西,有人能帮我纠正这个错误吗?
}
您无法从cin
提取到endl
,这没有任何意义。将endl
与输出流一起使用可以插入新行并刷新流。只需移除>> endl
s.
此外,您的length
拼写错误。
std::endl
用于输出流而非输入流。如果这对初学者来说有意义的话,我会反驳这一点,因为你可以将换行符(如果你想从用户那里获取输入,大多数时候都必须这样做)放入输入流中,但std::endl
根本不适用于std::cin
。
此外,我相信您并不真的需要这样做,因为当您按下"Enter"键来确认您输入的换行符也被打印到输出流中时。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 是std :: set&lt; std :: future&gt;不可能存在
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- 使用 std::vector<boost::shared_ptr<Base_Class>> 或 boost::p tr_vector 的性能注意事项是什么<Base>
- std::map<std::set, double> AND std:<long>map< std::p air<long, long>, double>
- 如何获取std::vector<DMatch>