本文介绍了将TCHAR转换为C ++中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图将TCHAR转换为如下字符串:

I'm trying to convert a TCHAR to a string as in:

std::string mypath;
TCHAR path[MAX_PATH];
GetModuleFileName( NULL, path, MAX_PATH );

我需要将 mypath path 。我做了一个简单的循环,并连接 path [index] mypath ,这是可行的,但我不喜欢这种方式。

I need to set mypath to that of path. I did a simple loop and concatenated path[index] to mypath and this works but I don't like this way.

我是C ++的新手,但是做了大量的C#。我看过在char中传递的 GetModuleFileName 的例子,但它不喜欢。它需要 TCHAR LPWSTR

I'm new to C++ but have done plenty of C#. I've seen examples of the GetModuleFileName that passes in a "char" but it doesn't like it. It needs the TCHAR or a LPWSTR.

推荐答案

TCHAR是一个宏,定义为char或wchar,取决于您定义的字符集。 2008之后的默认值是将字符设置为unicode。如果您更改字符集,则此代码适用。

TCHAR is a macro defined as a char or wchar depending on what you have your character set defined to. The default after 2008 is have the character set to unicode. this code works if you change your character set.

int _tmain(int argc, _TCHAR* argv[])
{
    TCHAR* bob ="hi";
    string s = bob;
}

右键单击项目设置并修改下面的

Right click on the project settings and chage the folowing

>

如果要将TCHAR用作Unicode字符集,请使用

if You want to use TCHAR as a Unicode character set use wstring

这篇关于将TCHAR转换为C ++中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 16:18