Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi everybody
this is code of backspace button (just delete last character) in calculator , in MFC(C++)
it hase error...I will be happy if you guide me
thank you

C#
UpdateData(TRUE);
int n=strlen(m_strNumber);   // n is length of editbox
for(int i=0;i<n-1;i++)
{
    m_strNumber[i+1]=m_strNumber[i]; // error : expression must be modifiable lvalue
}

UpdateData(FALSE);
Posted
Updated 10-Nov-13 9:45am
v3
Comments
CHill60 10-Nov-13 14:18pm    
And what is the error?
CHill60 10-Nov-13 14:31pm    
And having looked at it again, this will not delete the last character
Diba.S 10-Nov-13 15:11pm    
erroe: expression must be modifiable
I'm not sure about this code but I think it's true and because don't understand what is problem I asked you guide me . and why you say it doesn't delete last character?,could you please tell more?
CHill60 10-Nov-13 15:22pm    
All you are doing is resetting the characters following the one at index i ... e.g. if m_strNumber is "123" then when i = 0 you are trying to set m_strNumber to "113", when i = 1 m_strNumber becomes "111". I would have thought that you would just want to remove the last character in the string (or move the null back 1 position).
As to the error ... how have you declared m_strNumber?
Diba.S 10-Nov-13 15:30pm    
emmm...yes,as you explain I did wrong... :/ now could you tell me how should I change the code?

1 solution

Assuming that m_strNumber is a character array then:
C++
m_strNumber[n - 1] = '\0';

If it is a CString then
C++
m_strNumber = m_strNumber.Left(n - 1);
 
Share this answer
 
Comments
CPallini 11-Nov-13 4:30am    
5.
Diba.S 26-Nov-13 13:48pm    
thank u Richard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900