Search code examples
windowsmfcatoi

MFC CString to int


using this code i get an error at atoi's conversion from CString to int:

    int nrCentrala; CString idCentrala;
    GetDlgItem(IDC_EDIT_IDCENTRALA)->GetWindowText(idCentrala);
    nrCentrala = atoi(&idCentrala);

where IDC_EDIT_IDCENTRALA is an edit control.

Error 7 error C2664: 'atoi' : cannot convert parameter 1 from 'CString *' to 'const char *'


Solution

  • You pass pointer to CString (CString* type) instead of const char* which is expected by atoi(). Correct call is nrCentrala = atoi(idCentrala.GetString());