我想從字符串轉換爲整數,所以我在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;
爲什麼地球上你首先要調用這個函數?你爲什麼不使用慣用的方式將文本轉換爲整數? –