我試圖從stdin中取出wchar_t
字符串,然後通過函數將其從Unicode轉換爲ASCII。Unicode到ASCII轉換後聲明std :: string給出分割錯誤
該函數在某種程度上不允許我在程序中進一步使用std :: string。
#include <iostream>
#include <string>
#include <locale>
#include <cstring>
#include <cwchar>
using namespace std;
bool UnicodeToAscii(wchar_t* szUnicode, char* szAscii);
int main()
{
wchar_t w[100];
wcin>>w;
char* c;
bool x=UnicodeToAscii(w,c);
cout<<c<<"\n";
string s="hi";
return 0;
}
bool UnicodeToAscii(wchar_t* szUnicode, char* szAscii)
{
int len, i;
if((szUnicode == NULL) || (szAscii == NULL))
return false;
len = wcslen(szUnicode);
for(i=0;i<len+1;i++)
*szAscii++ = static_cast<char>(*szUnicode++);
return true;
}
你是**不** **在這裏將任何Unicode編碼轉換爲ASCII。 Unicode更復雜。 – deviantfan 2015-04-05 18:24:35
除此之外,您的測試輸入將有所幫助。這可能是原因。 – deviantfan 2015-04-05 18:25:45
好的,這可能是錯誤的,但我試圖在函數中將** wchar_t **轉換爲** char **,然後我無法在我的程序中使用std :: string。這很奇怪.. – 2015-04-05 18:27:17