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:
#include <iostream>
#include <istream>
#include <ostream>
int main ()
{
std::cin >> "Hello, please enter your name: ";
return 0;
}
I’ve tried:
using namespace std
- Obviously, as you can see, including
<istream>
and<ostream>
separately, as well as along with different libraries - 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";
}
}