I am getting an error c2678 binary'>>': no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
Also i am getting an error c2065 'north':undeclared identifier.
if you cant tell by the code that i have and the "dialogue" I am trying to "move" to area 2 almost like they do in Zork. But i am having trouble finding the means to do so. Any help would be really appreciated.
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
usingnamespace std;
int main()
{
wchar_t direction;
cout << "Welcome to a world of imagination. You are in Area 1." << endl
<< "Go North to Area 2." << endl;
cin >> direction;
if (direction = north)
{
cout << "Good you made it to Area 2." << endl;
}
else
{
cout << "No you imbecile the only way out of Area 1 is to go North."
<< endl;
}
system("PAUSE");
return 0;
}
To get a wchar_t you need to use std::wcin, not std::cin. wcin >> direction;
= is the assignment operator, not the "equals" comparison operator (==).
Making a comparison with a wchar_t you need to use a wide char character constant. if (direction == L"n" || direction == L"N")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
int main()
{
std::cout << "Welcome to a world of imagination. You are in Area 1." << std::endl
<< "Go North to Area 2." << std::endl;
wchar_t direction;
std::wcin >> direction;
if (direction == L'n' || direction == L'N')
{
std::cout << "Good you made it to Area 2." << std::endl;
}
else
{
std::cout << "No you imbecile the only way out of Area 1 is to go North."
<< std::endl;
}
}
Welcome to a world of imagination. You are in Area 1.
Go North to Area 2.
n
Good you made it to Area 2.
Why are you using a wchar_t instead of a char?
Using a std::string would be better, the user can enter more than one character.
Yes that works. Also while i was waiting for reply I was fiddling with the code and changed the variable type to string and it worked as well. I understand i didnt have north declared but what i dont understand is why now is the error c2678 gone?
You didn't declare the variable 'north'. But there is a quick way to fix it :
And if north is supposed to be a string constant? By the context that would be a reasonable conjecture (direction being a character variable), so redefining to an integer variable could be a step back instead of merely enclosing north in quotes: "north",
@FurryGuy
Concerning your earlier post telling me if(direction == L'n' || direction == L'N') how would I apply that same outcome if i was to change wchar_t direction; to string direction;? Because as you said the user could input more than just a letter.
> How would I apply that same outcome if i was to change (wchar_t direction) to (string direction)?
You can use this : if(direction[0] == L'n'|| direction[0] == L'N')