I am trying to make a text based game to help build my c ++ knowledge. I just started and I am already running into problems. When I build my code I get an error on the cin line. it says "|error: no match for 'operator<<' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'int')| "
what have I done wrong? I am trying to ask the player there name and then have it print the name they entered.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int yn;
cout << "Enter name ";
cin >> yn;
cout << "entered" << yn;
}
Well, as we can't actually see the code you used to get this, that won't be much help.
If yn is an int, then what sort of value do you think you can input into it? Certainly not "Help". Maybe you intended a variable type of string (or, if you really only intended to input a y or a n, then a char would do).
I'm staggered it took 4.7s to run, though. Perhaps you're using Visual Studio.
Its the code from above. I am trying to have the user put in a name and then it print out the name the user chose. I just typed Help in the command box for the name.
Have you ever tested input two words with a space between them?like "John Doe",if you use cin,you will find the output name is not as you expect,it will be John.In view of this problem,i suggest you using getline (cin, yn) instead of cin>>yn,then no matter how many words you input and how many space between every two words,the result will still as you expect.