简体   繁体   中英

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??" im a beginner at c++ but still what the hell.

also this error: "In function '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. cin is an input stream. I'm not sure what you expect endl to do here:

cin >> totalmilk >> endl;

But it's wrong.

This is the problem

cin >> totalmilk >> endl;

It is giving error because of endl. Remove it.

operator<< has an overload that takes a function pointer to a function that receives an std::basic_ostream . This allows you to use "stream manipulators", ie std::endl , in a operator<< chain. 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 . However, it also returns one by reference (similar to operator<< ), meaning it can appear in a chain, ie std::cout << std::endl .

Since std::cin is a std::basic_istream , you have incompatible arguments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM