[英]no match for 'operator>>' in 'std::cin?
simple program tells u how much milk costs whatever i dont get why i get this error "no match for 'operator>>' in 'std::cin??" 一个简单的程序告诉您我不知道要花多少牛奶费用,为什么我会收到此错误“ std :: cin中的'operator >>'不匹配?” im a beginner at c++ but still what the hell. 我是C ++的初学者,但仍然如何。
also this error: "In function 'int main()':" 也会出现此错误:“在函数'int main()'中:”
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
const double CARTONLOAD = 3.78;
const double CARTONCOST = 3.78 * .38;
const double CARTONPROFIT = 0.27;
int main()
{
double totalmilk = 0;
double milkcartonsneeded = 0;
double milkcost = 0;
cout << "Enter total amount of milk produced in the morning in Liters" << endl;
cin >> totalmilk >> endl;
milkcartonsneeded = totalmilk/CARTONLOAD;
cout << " Number of milk cartons needed to hold milk: " << milkcartonsneeded << endl;
milkcost = milkcartonsneeded * CARTONCOST;
cout << " The cost of producing milk is: " << milkcost << endl;
cout << " The profit for producing milk is: " << milkcartonsneeded * CARTONPROFIT - milkcost << endl;
return 0;
}
endl
is an output stream manipulator. endl
是输出流操纵器。 cin
is an input stream. cin
是输入流。 I'm not sure what you expect endl
to do here: 我不确定您期望endl
在这里做什么:
cin >> totalmilk >> endl;
But it's wrong. 但这是错误的。
This is the problem 这就是问题
cin >> totalmilk >> endl;
It is giving error because of endl. 由于endl,它给出了错误。 Remove it. 去掉它。
operator<<
has an overload that takes a function pointer to a function that receives an std::basic_ostream
. operator<<
具有一个重载,该重载使用函数指针指向接收std::basic_ostream
的函数。 This allows you to use "stream manipulators", ie std::endl
, in a operator<<
chain. 这使您可以在operator<<
链中使用“流操纵器”,即std::endl
。 This allows you to do the following for example: 例如,这使您可以执行以下操作:
std::cout << "hey.";
std::endl(std::cout);
std::cout << "hello.";
Because std::endl
is just a function that takes a std::basic_ostream
. 因为std::endl
只是一个带有std::basic_ostream
的函数。 However, it also returns one by reference (similar to operator<<
), meaning it can appear in a chain, ie std::cout << std::endl
. 但是,它也通过引用返回一个值(类似于operator<<
),这意味着它可以出现在链中,即std::cout << std::endl
。
Since std::cin
is a std::basic_istream
, you have incompatible arguments. 由于std::cin
是std::basic_istream
,因此您具有不兼容的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.