本文介绍了将char *转换为char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正在使用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提前, 克里斯 解决方案 您需要检查文本的类型。来自 " 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常见问题: 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图书馆书籍 你想在这做什么?你想要投入什么价值 outBuffer [0]以及为什么? john Hi all,I''m using C++ Builder5. I want to get data from an edit-box andsend it to a development kit. The dev-kit can only receive charand 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 anyonehave a solution for my problem?So I just need to get a byte from the edit-box and store thisin 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 amethod to access individual characters. If thetype 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 forsuggested newsgroups.--Thomas MatthewsC++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txtC++ Faq: http://www.parashift.com/c++-faq-liteC Faq: http://www.eskimo.com/~scs/c-faq/top.htmlalt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.htmlOther sites: http://www.josuttis.com -- C++ STL Library bookWhat are you trying to do here? What value are you trying to put intooutBuffer[0] and why?john 这篇关于将char *转换为char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!