wchar_t* to char* under Windows

Source: Internet
Author: User

This is common in windows, often, leaving a file.

This function is generally used:

size_t wcstombs (   char *mbstr,   const wchar_t *WCSTR,   size_t count);

Mbstr

The address of a sequence of multibyte characters.

Wcstr

The address of a sequence of wide characters.

Count

The maximum number of bytes that can is stored in the multibyte output string.

Locale

The locale to use.

Here is a test I wrote, which was changed according to the project:

1#include <windows.h>2#include <string.h>3#include <stdio.h>4#include <stdlib.h>5#include <boost/filesystem.hpp>6 7 namespaceBFS =Boost::filesystem;8 9 Ten BOOLGet_path (Char*file_name,size_t size) { One  A  - CharOwnpth[max_path]; -  thehmodule hmodule = GetModuleHandle (NULL);//Would contain exe Path,when passing NULL to GetModuleHandle, it returns handle of EXE itself - if(Hmodule! =NULL) - { -GetModuleFileNameA (hmodule,ownpth, MAX_PATH);//  + } - Else +ownpth[0]=0; A  at BFS::p ath Iic_file (ownpth); -Iic_file = Iic_file.parent_path ()/"DLP_USB.IIC";//For releaseing -  - if( !Bfs::is_regular_file (iic_file)) - { -printf"\r\nerror,open 68013 IIc file fail\r\n"); in return false ; - } to  +  - wcstombs (File_name,iic_file.c_str (), size); the  * //memcpy (File_name,iic_file.c_str (), byte_count); $ Panax Notoginseng return true; -  the } +  A intMain () { the  + Chariic_file[ +]; -  $ if(Get_path (Iic_file, +)){ $  -printf"true\n"); - } the  - return 0;Wuyi}

References

Http://msdn.microsoft.com/en-us/library/5d7tc9zw.aspx

http://blog.163.com/tianshi_17th/blog/static/4856418920085209414977/

wchar_t* to char* under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.