我剛從cplusplus複製一些代碼,並運行測試程序wctomb
:爲什麼MB_CUR_MAX是未定義的?
/* wctomb example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* wctomb, wchar_t(C) */
int main() {
const wchar_t str[] = L"wctomb example";
const wchar_t* pt;
char buffer [MB_CUR_MAX];
int i,length;
pt = str;
while (*pt) {
length = wctomb(buffer,*pt);
if (length<1) break;
for (i=0;i<length;++i) printf ("[%c]",buffer[i]);
++pt;
}
return 0;
}
然而,該方案不能被編譯,因爲MB_CUR_MAX是不確定的,只要我的編譯器(VC 2010)被認爲是。我想知道我該怎麼做。謝謝!
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'buffer' : unknown size