converting narrow string to wide string

前端 未结 9 1508
难免孤独
难免孤独 2020-12-06 11:57

How can i convert a narrow string to a wide string ?

I have tried this method :

string myName;
getline( cin , myName );
wst         


        
9条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 12:38

    Here are two functions that can be used: mbstowcs_s and wcstombs_s.

    mbstowcs_s: Converts a sequence of multibyte characters to a corresponding sequence of wide characters. wcstombs_s: Converts a sequence of wide characters to a corresponding sequence of multibyte characters.

    errno_t wcstombs_s(
       size_t *pReturnValue,
       char *mbstr,
       size_t sizeInBytes,
       const wchar_t *wcstr,
       size_t count 
    );
    
    errno_t mbstowcs_s(
       size_t *pReturnValue,
       wchar_t *wcstr,
       size_t sizeInWords,
       const char *mbstr,
       size_t count 
    

    );

    See http://msdn.microsoft.com/en-us/library/eyktyxsx.aspx and http://msdn.microsoft.com/en-us/library/s7wzt4be.aspx.

提交回复
热议问题