C++ Could not convert input string when using cin and variables -


i'm trying simple program user inputs string his/her name, if string equal name, executes different commands.

it's this:

#include <iostream> #include <string> #include <sstream>  using namespace std;  int main() {  string input = "";  cout << "what's name?:\n>";  getline(cin, input);  if(input = "micaela"){     cout << "you're best" << input << endl << endl; }  else     cout << "you kinda suck" << input << endl << endl; return 0; } 

when compiling, following error:

13 22 c:\users\francisco\desktop\cpp\holanena.cpp [error] not convert 'input.std::basic_string<_chart, _traits, _alloc>::operator=, std::allocator >(((const char*)"micaela"))' 'std::basic_string' 'bool'

the problem occurs in line

if(input = "micaela") 

which assigns "micaela" input. use comparison operator == instead of assignment operator = want:

if(input == "micaela") 

Popular posts from this blog