如何在unicode项目中将std:string转换为CString [英] How to convert std:string to CString in unicode project

查看:571
本文介绍了如何在unicode项目中将std:string转换为CString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 std :: string
我需要将 std:string 转换为 Cstring

我尝试使用 .c_str(),但它只适用于非unicode项目和我使用unicode项目(因为非unicode项目被depreceated VS2013)。

I try to use the .c_str() but it's only for non-unicode project and i use unicode project ( because non unicode project are depreceated wiht VS2013).

任何人都可以显示如何将 std :: string 转换为 CString 在unicode项目中?

Anyone could show my how to convert an std::string to a CString in unicode project ?

推荐答案

c>有一个转换构造函数接受 const char * CStringT :: CStringT )将 std :: string 转换为 CString 的过程非常简单:

CString has a conversion constructor taking a const char* (CStringT::CStringT). Converting a std::string to a CString is as simple as:

std::string stdstr("foo");
CString cstr(stdstr.c_str());

这适用于UNICODE和MBCS项目。如果 std :: string 包含嵌入的 NUL 字符,那么必须使用具有长度参数的转换构造函数: p>

This works for both UNICODE and MBCS projects. If your std::string contains embedded NUL characters you have to use a conversion constructor with a length argument:

std::string stdstr("foo");
stdstr += '\0';
stdstr += "bar";
CString cstr(stdstr.c_str(), stdstr.length());

这篇关于如何在unicode项目中将std:string转换为CString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆