When do we get \"l-value required\" error...while compiling C++ program???(i am using VC++ )
You are trying to use an invalid value for an l-value somewhere in your code. An l-value is an expression to which a value can be assigned.
For example, you might have a statement like the following:
10 = x;
where you should instead have:
x = 10;
Although it is probably not this obvious in your case.
This happen when you try manipulate the value of a constant may it be increments or decrements which is not allowed. `
#define MAX 10
void main(){
int num;
num = ++MAX;
cout<<num;
}
I had a similar issue and I found that the problem was I used a single '=' instead of a double '==' in an if statement
lvalue error:
if (n = 100) { code } // this is incorrect and comes back with the lvalue error
correct:
if (n == 100) { code } // this resolved my issue
take for example
*int a=10,b=20;
int c=++(ab+1); above code will give error because inside the bracket you have a expression ont which you want to do increment operation which is not possible. So before doing doing that you have to store that value to some variable.so above code will error of "lvalue" required.
Actually, this error occurs very often when you don't put a ";" and not to declare a variable that was probably prior to the variable that gives this error, not to declare throws this error since it cannot assign a value to a variable that was not declared ... smart boy!
Typically one unaccustomed to C++ might code
if ((x+1)=72) ...
in place of
if ((x+1)==72) ...
the first means assign 72 to x+1 (clearly invalid) as opposed to testing for equality between 72 and (x+1)