2017-01-29 45 views
-2

我想從字符串轉換爲整數,所以我在winapi中使用了atoi(),如下所示。 當我使用的atoi功能,我碰到這個錯誤信息win32 atoi問題無法將參數1從'wchar_t [5]'轉換爲'const char *

1>d:\work\usb\isp1\isp1\source1.cpp(771): error C2664: 'int atoi(const char *)' : cannot convert argument 1 from 'wchar_t [5]' to 'const char *' 
1>   Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 

如何將字符串轉換爲整數?

HWND hEdit_a; 
HWND hEdit_d; 
wchar_t str_a[5]; 
wchar_t str_d[5]; 

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) 
{ 


    HDC hdc; 
    PAINTSTRUCT ps; 
    static HANDLE hTimer; 
    switch (iMessage) 
    { 
    case WM_CREATE: 

case ID_EDIT_A: 
     switch (HIWORD(wParam)) { 
     case EN_CHANGE: 
      GetWindowText(hEdit_a, str_a, 5); 
      //SetWindowText(hWnd, str_a); 
     } 
     break; 

.... 
case 4: //single i2c write 
      int ii; 
      int iii; 
      ii = atoi(str_a); 
      iii = atoi(str_d); 

      write_i2c() 
      break; 
+0

爲什麼地球上你首先要調用這個函數?你爲什麼不使用慣用的方式將文本轉換爲整數? –

回答

0

atoi是針對const char *字符串;你有什麼是一個wchar_t字符串。 charwchar_t不可互換。使用wchar_t字符串的相應功能; _wtoi

ii = _wtoi(str_a); 
iii = _wtoi(str_d); 
+0

謝謝,但我有下面的錯誤信息1> d:\ work \ usb \ isp1 \ isp1 \ source1.cpp(771):錯誤C3861:'wtoi':標識符未找到 – foe1

+0

'_wtoi'不'wtoi' –

+0

@ foe1在一個新問題中,這可能是最好的問題。 –

相關問題