I am a newbee in C++. Tried the following code:
while((char c = cin.get()) != 'q')
{ //do anything
}
when I try to compile, it fails with following
error: expected primary-expression before “char”.
Please help me understand this
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot have a declaration as a part of an expression.
You can have a declaration directly inside the parentheses of the loop (not in any nested parentheses):
but this stops on
!c, which is not what you want.This will work:
and so will this:
Update: see also this SO question.