Error. C++. Expected primary-expression before ')' token -


i wrote simple program , met error in switch. wrong?

error: expected primary-expression before ')' token

#include <iostream> #include <list> using namespace std;  int main() {     list<string> mylist;      string s;     while (true) {         cin >> s;         switch(s) {             case "quit":             break;              default:             mylist.push_back(s);             break;         }     } } 

thanks.

the real problem here:

 switch(s) { 

you cannot use strings in switch case.

alternative:

an if-else ladder. since have 1 case, use if statement it. example:

if (s=="quit") {     break; }  else      mylist.push_back(s); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -