wchar_t* 与char* 如何转换?

foshanzhuifeng 2010-12-03 04:31:45
请教一下各位,如题示:不用MultiByteToWideChar和WideCharToMultiByte如何转换
...全文
369 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
辰岡墨竹 2010-12-03
  • 打赏
  • 举报
回复
wchar_t是UTF-16编码的Unicode,基本上常用的Unicode字符如中文、英文都是两个字节一个字符,字符编码是统一的,是32位Windows的内部字符存储方式。
char是兼容以前系统的多字节字符集,,根据本地的代码页来决定字符。不同代码页中字符的存储方式不一致,也就会出现GB2312、Big5等不兼容的问题(一般英文1个字节,汉字2个字节),而且对于某些英文软件会无法正确处理多字节字符的,导致汉字被分割。
foshanzhuifeng 2010-12-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 s393102639 的回复:]

wchar_t用来表示中文 日文这些
[/Quote]
但是如果我把中文放进char*,好像也是存的了的
  • 打赏
  • 举报
回复
char 一个字节 是8位的二进制数 有256个
wchar_t 两个字节 是16位的二进制数 有256*256个
s393102639 2010-12-03
  • 打赏
  • 举报
回复
wchar_t用来表示中文 日文这些
foshanzhuifeng 2010-12-03
  • 打赏
  • 举报
回复
多谢大家!
IMPORT_C int mbtowc(wchar_t *pwc, const char *s, size_t n);
Description
Converts the multibyte character addressed by s into the corresponding UNICODE character pwc



我还有一事不明,请教一下大家。就是wchar_t是unicode码,理不清那些编码的关系?能否略微解释一下
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 freezezdj 的回复:]

mbtowc和wctomb
[/Quote]

up。。
luciferisnotsatan 2010-12-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 freezezdj 的回复:]

mbtowc和wctomb
[/Quote]
正解,不能用微软的,那就用C标准库好了
qwer_boo 2010-12-03
  • 打赏
  • 举报
回复
没人会吗
冻结 2010-12-03
  • 打赏
  • 举报
回复
mbtowc和wctomb
// // FilePath.h // /** \file FilePath.h */ #pragma once #include "vtString.h" #include #include /** * A portable class for reading directory contents. * * Example of use: \code for (dir_iter it("C:/temp"); it != dir_iter(); ++it) { if (it.is_hidden()) continue; if (it.is_directory()) printf("Directory: '%s'\n", it.filename().c_str()); else printf("File: '%s'\n", it.filename().c_str()); } \endcode */ class dir_iter { public: dir_iter(); dir_iter(const char*dirname); dir_iter(const wchar_t*dirname); ~dir_iter(); /// Returns true if the current object is a directory. bool is_directory(); /// Returns true if the current object is hidden. bool is_hidden(); /// Get the filename fo the current object. std::string filename(); std::wstring wfilename(); // Iterate the object to the next file/directory. void operator++(); // Test for inequality useful to test when iteration is finished. bool operator!=(const dir_iter ⁢); long m_handle; private: struct _wfinddata_t m_data; }; //MBCS string 或者 Wide string vtString vtFindFileOnPaths(const vtStringArray &paths;, const char *filename); vtString2 vtFindFileOnPaths(const vtStringArray2 &paths;, const wchar_t *filename); bool vtCreateDir(const char *dirname); bool vtCreateDir(const wchar_t *dirname); void vtDestroyDir(const char *dirname); void vtDestroyDir(const wchar_t *dirname); int vtDeleteFile(const char *filename); int vtDeleteFile(const wchar_t *filename); const char *vtStartOfFileName(const char *szFullPath); const wchar_t *vtStartOfFileName(const wchar_t *szFullPath); vtString vtExtractPath(const char *szFullPath, bool bTrailingSlash); vtString2 vtExtractPath(const wchar_t *szFullPath, bool bTrailingSlash); bool vtPathIsAbsolute(const char *szPath); bool vtPathIsAbsolute(const wchar_t *szPath); vtString vtPathLevelUp(const char *src); vtString2 vtPathLevelUp(const wchar_t *src); vtString get_line_from_stream(std::ifstream &input;); vtString2 get_line_from_stream(std::wifstream &input;); //bFull为ture包括所有扩展名;否则最后一个扩展名 void vtRemoveFileExtensions(vtString& fname,bool bFull = false); void vtRemoveFileExtensions(vtString2& fname,bool bFull = false); //bFull为ture包括所有扩展名;否则最后一个扩展名 vtString vtGetExtensions(const vtString &fname;, bool bFull = false); vtString2 vtGetExtensions(const vtString2 &fname;, bool bFull = false); bool vtChangeFileExtension(vtString& input, const char *extension); bool vtChangeFileExtension(vtString2& input, const wchar_t *extension); bool vtFileExists(const char *fname); bool vtFileExists(const wchar_t *fname); #pragma comment(lib, "shell32.lib") bool vtCopyFile( const char* from,const char * to, bool bFailIfExists=true); bool vtCopyFile( const wchar_t* from,const wchar_t * to, bool bFailIfExists=true); bool vtCopyTree(const char* from,const char * to); bool vtCopyTree(const wchar_t* from,const wchar_t * to); bool vtFolderExists(const char *fname); bool vtFolderExists(const wchar_t *fname); bool vtFilePathExists(const char *fname); bool vtFilePathExists(const wchar_t *fname); int vtGetFileSize(const char *fname); int vtGetFileSize(const wchar_t *fname); void vtSetEnvironmentVar(const char* var, const char*value); void vtSetEnvironmentVar(const wchar_t* var, const wchar_t*value); #include "windows.h" bool vtGetModuleFullPath(const char* modulename,vtString& fullpath); bool vtGetModuleFullPath(const wchar_t* modulename,vtString2& fullpath); ///////////////////////////////////////////// // Open a file using a UTF-8 or wide character filename. FILE *vtFileOpen(const char *fname_mbcs, const char *mode); FILE *vtFileOpen(const wchar_t *fname_wide, const wchar_t *mode); vtString vtChooseFolder(HWND hWnd =NULL); vtString2 vtChooseFolder2(HWND hWnd=NULL);

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧