将char *转换为char [英] Converting char* to char

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

问题描述

大家好,

我正在使用C ++ Builder5。我想从编辑框中获取数据,然后将
发送到开发工具包。开发工具包只能收到char

而且没有char *


这里是我代码的一部分:


char * Data_byte = 0x00;


UCHAR outBuffer [64];

WORD outPacketSize;

outBuffer [0] = Data_byte;

...

...

void __fastcall TForm1 :: Data_EditChange(TObject * Sender)

{

Data_byte = Data_Edit-> Text.c_str();

}


我收到错误 - > ;无法将char *转换为char。有没有人

有一个解决我的问题的方法?

所以我只需要从编辑框中获取一个字节并存储这个

in一个变量。


thnx提前,

克里斯

解决方案

Chris在线写道:

大家好,
我正在使用C ++ Builder5。我想从编辑框中获取数据并将其发送到开发工具包。开发工具包只能收到char
而且没有char *

这里是我代码的一部分:

char * Data_byte = 0x00;

UCHAR outBuffer [64];
WORD outPacketSize;
outBuffer [0] = Data_byte;
..
..
void __fastcall TForm1 :: Data_EditChange(TObject * Sender)
{Data_byte = Data_Edit-> Text.c_str();
}

我收到错误 - >无法将char *转换为char。有没有人能解决我的问题?
所以我只需要从编辑框中获取一个字节并将其存储在一个变量中。

thnx提前,
Chris




您需要检查文本的类型。来自

" Data_Edit"控制以查看字符串类型是否具有访问单个字符的

方法。如果

类型是std :: string,你可以使用:

{

Data_byte = Data_Edit-> Text [0];

}

但是,唉,Borland可能有自己的字符串类型。


您也可以在Borland新闻组发布。

查看下面的C ++ FAQ和welcome.txt

建议的新闻组。


-

Thomas Matthews


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt

C ++常见问题: http://www.parashift.com/c++-faq-lite

C常见问题:< a rel =nofollowhref =http://www.eskimo.com/~scs/c-faq/top.htmltarget =_ blank> http://www.eskimo.com/~scs/c -faq / top.html

alt.comp.lang.learn.c-c ++ faq:
http:// w ww.raos.demon.uk/acllc-c++/faq.html

其他网站:
http://www.josuttis.com - C ++ STL图书馆书籍


Chris Online写道:

char * Data_byte = 0x00;

UCHAR outBuffer [64];
WORD outPacketSize;
outBuffer [0] = Data_byte;




你想在这做什么?你想要投入什么价值

outBuffer [0]以及为什么?




" Chris Online" ; < CV ******* @ hotmail.com>在消息中写道

news:87 ************************** @ posting.google.c om ...

大家好,我正在使用C ++ Builder5。我想从编辑框中获取数据并将其发送到开发工具包。开发工具包只能接收char
而且没有char *

这里是我的代码的一部分:

char * Data_byte = 0x00;


我假设这是一个错误的类型


char Data_byte = 0x00;

UCHAR outBuffer [ 64];
WORD outPacketSize;
outBuffer [0] = Data_byte;
..
..
void __fastcall TForm1 :: Data_EditChange(TObject * Sender)
{
Data_byte = Data_Edit-> Text.c_str();
}
我收到错误 - >无法将char *转换为char。有没有人能解决我的问题?
所以我只需要从编辑框中获取一个字节并将其存储在一个变量中。


好​​好想想吧。编辑框可以包含多个字符这就是为什么

Data_Edit-> Text是一个字符串(可能,你没说)。你想要一个

字符,但是哪一个?第一个,第二个,最后一个,第一个

这不是一个空间,到底是什么?这不仅仅是关于我如何将
a char *转换为char,没有通用的方法可以做到这一点,这是一个定义你的b
$ b问题更清楚一点。


FWIW您可以使用[]运算符索引字符串


Data_byte = Data_Edit-> Text [0 ] //字符串中的第一个字符


thnx提前,
Chris




john


Hi all,
I''m using C++ Builder5. I want to get data from an edit-box and
send it to a development kit. The dev-kit can only receive char
and no char*

here''s a part of my code:

char* Data_byte = 0x00;

UCHAR outBuffer[64];
WORD outPacketSize;
outBuffer[0] = Data_byte;
...
...
void __fastcall TForm1::Data_EditChange(TObject *Sender)
{
Data_byte=Data_Edit->Text.c_str();
}

I get an error -> Can''t convert char* to char. Does anyone
have a solution for my problem?
So I just need to get a byte from the edit-box and store this
in a variable.

thnx in advance,
Chris

解决方案

Chris Online wrote:

Hi all,
I''m using C++ Builder5. I want to get data from an edit-box and
send it to a development kit. The dev-kit can only receive char
and no char*

here''s a part of my code:

char* Data_byte = 0x00;

UCHAR outBuffer[64];
WORD outPacketSize;
outBuffer[0] = Data_byte;
..
..
void __fastcall TForm1::Data_EditChange(TObject *Sender)
{
Data_byte=Data_Edit->Text.c_str();
}

I get an error -> Can''t convert char* to char. Does anyone
have a solution for my problem?
So I just need to get a byte from the edit-box and store this
in a variable.

thnx in advance,
Chris



You will need to check the type of "Text" from the
"Data_Edit" control to see if the string type has a
method to access individual characters. If the
type was std::string, you could use:
{
Data_byte = Data_Edit->Text[0];
}
But alas, Borland may have its own string type.

You could also post this at a Borland newsgroup.
Check the C++ FAQ and welcome.txt below for
suggested newsgroups.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


Chris Online wrote:

char* Data_byte = 0x00;

UCHAR outBuffer[64];
WORD outPacketSize;
outBuffer[0] = Data_byte;



What are you trying to do here? What value are you trying to put into
outBuffer[0] and why?



"Chris Online" <cv*******@hotmail.com> wrote in message
news:87**************************@posting.google.c om...

Hi all,
I''m using C++ Builder5. I want to get data from an edit-box and
send it to a development kit. The dev-kit can only receive char
and no char*

here''s a part of my code:

char* Data_byte = 0x00;
I''m assuming this is a mistype for

char Data_byte = 0x00;

UCHAR outBuffer[64];
WORD outPacketSize;
outBuffer[0] = Data_byte;
..
..
void __fastcall TForm1::Data_EditChange(TObject *Sender)
{
Data_byte=Data_Edit->Text.c_str();
}

I get an error -> Can''t convert char* to char. Does anyone
have a solution for my problem?
So I just need to get a byte from the edit-box and store this
in a variable.

Well think about it. An edit box can contain multiple characters That''s why
Data_Edit->Text is a string (probably, you didn''t say). You want one
character, but which one? The first, the second, the last, the first one
that isn''t a space, what exactly? It''s not just a matter of how do I convert
a char* to a char, there is no universal way to do that, its a matter of
defining your problem a little more clearly.

FWIW you can index a string using the [] operator

Data_byte = Data_Edit->Text[0] // the first character from the string

thnx in advance,
Chris



john


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

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