Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

no match for 'operator>>' when using simple 'std::cin' operation

The syntax error returned is:

no match for ‘operator>>’ (operand types are ‘std::istream {aka std::basic_istream<char>}’ and ‘const char[32]’)

Source which is returning the syntax error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream>
#include <istream>
#include <ostream>

int main ()
{   
    std::cin >> "Hello, please enter your name: ";

    return 0;
}

I’ve tried:

  1. using namespace std
  2. Obviously, as you can see, including <istream> and <ostream> separately, as well as along with different libraries
  3. including <iostream> by itself with no other libraries operating

I’m still fairly new, so that’s all I could think to try.

Can someone tell me what I am overlooking?

>Solution :

To read from a stream, you must provide a variable that will accept the value. Your problem is you’ve provided a string literal. That makes no sense. Where do you expect the data to be stored, and what type should it be?

Probably what you wanted is something like this:

#include <iostream>
#include <string>

int main() {
    std::cout << "Hello, please enter your name: ";
    std::string name;
    if (std::getline(std::cin, name)) {
        std::cout << "Hello, " << name << "\n";
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading