C ++将char转换为const char * [英] C++ Converting a char to a const char *

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

问题描述

我正在尝试使用beginthreadex创建一个线程,该线程将运行一个以char作为参数的函数.我对C ++不好,但是我不知道如何将char变成const char ,这是beginthreadex需要它的参数的.有没有办法做到这一点?对于将char转换为const char 而不是将其转换为const char *,我发现了很多问题.

I'm trying to use beginthreadex to create a thread that will run a function that takes a char as an argument. I'm bad at C++, though, and I can't figure out how to turn a char into a const char , which beginthreadex needs for its argument. Is there a way to do that? I find a lot of questions for converting a char to a const char, but not to a const char *.

推荐答案

char a = 'z';
const char *b = &a;

当然,这是在堆栈上.如果您需要在堆上使用它,

Of course, this is on the stack. If you need it on the heap,

char a = 'z';
const char *b = new char(a);

这篇关于C ++将char转换为const char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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