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
Post a Comment