Help

May someone tell me why my code is not working correctly, when I attempt to compile it it gives me the error of not being able to transfer the
"if (decisiondata = 1)" into a bool (I'm assuming that means boolean term).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <iostream>
#include <sstream> 
#include <string>
#include <cctype>
int main ()
{ 
    //beginning sequence 
using namespace std;
string namedata;
cout << "SINBAD: You traveller, what is your name?" << endl;
cout << "NAME: ", 
getline(std::cin, namedata);
cout << "SINBAD: Well " << namedata << " you will be the first man I slay today, feel privileged." << endl;
string decisiondata;
cout << "{-} You carefully approach Sinbad and prepare yourself." << endl;
cout << "{-} [1] Fight  or  [2] Run" << endl;
cout << "{-} What will you choose ?: "; getline (cin,decisiondata);

if (decisiondata = 1)

return 0; 
}
= is assignment
== is comparison

1 is a number
"1" is a string literal
decisiondata is a std::string.

A std::string does not evaluate to true or false


> it gives me the error of not being able to transfer the "if (decisiondata = 1)" into a bool
if you don't understand the error message, don't paraphrase it, post it fully
foo.cpp:19:6: error: value of type 'std::basic_string<char>' is not contextually convertible to 'bool'
Last edited on
Topic archived. No new replies allowed.