类型转换问题(字符编码?)(SDL_ttf显示汉字)
SDL_ttf扩展库问题:
在网上找了快两天了,一直没解决:
如果直接在代码中写入汉字:
std::string text_="汉字一二:";
message=TTF_RenderUTF8_Solid(font,text_.c_str(),textColor);
SDL_BlitSurface(message,NULL,screen,NULL);
则程序运行时"汉字一二"可以正常显示.
而当std::string text是从文件中读取时:
std::ifstream fin("file.txt");
std::string text;
fin>>text;
message=TTF_RenderUTF8_Solid(font,text.c_str(),textColor);
SDL_BlitSurface(message,NULL,screen,NULL);
却不能显示file.txt文件中的汉字,我将file.txt的编码方式从ANSI,UNICODE,UTF8都试过了,当使用ANSI时,可以正常显示文件中的英文字母数字等,不能显示汉字,当使用另外两种编码时,直接什么都显示不了,连英文都显示不了.
如果用另一个函数:
std::ifstream fin("file.txt");
std::string text;
fin>>text;
message=TTF_RenderUNICODE_Solid(font,text.c_str(),textColor);
SDL_BlitSurface(message,NULL,screen,NULL);
则编译时会提示
77 V:\project\Untitled1.cpp cannot convert `const char*' to `const Uint16*' for argument `2' to `SDL_Surface* TTF_RenderUNICODE_Solid(TTF_Font*, const Uint16*, SDL_Color)'
这种情况应该如何解决呢?
附:
SDL_Surface *TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg);
SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font, const Uint16 *text, SDL_Color fg);
SDL_Surface *TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg);