怎样把文本框里的string 存到char 指中

wide288 2003-09-11 12:50:01
谢谢了。如:
char *sp;
*sp = &(Edit->Text);
可是报错。
...全文
37 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wide288 2003-09-12
  • 打赏
  • 举报
回复
谢谢大家的帮助。我想这个问题,已经解决。
不过程序还没有通过,是因为一个全局没有定义成功。正在解决,再次谢谢大家了。
halibut 2003-09-11
  • 打赏
  • 举报
回复
char buf[100];
memset(buf,0,100);
memcpy(buf,Edit->Text.c_str(),Edit->Text.Length());
netsys2 2003-09-11
  • 打赏
  • 举报
回复
char *sp;
sp = Edit->Text.c_str();
Robin 2003-09-11
  • 打赏
  • 举报
回复
:>
binbin 2003-09-11
  • 打赏
  • 举报
回复
楼主抄都抄错,我还能说什么呢?
看看这里吧.
http://expert.csdn.net/Expert/topic/2233/2233719.xml?temp=.7872278
pjm02 2003-09-11
  • 打赏
  • 举报
回复
wide288(鱼) 你犯的错误是这样的:
1.) char *sp = new char[Edit1->Length()+1]; 应该该成
char *sp = new char[ Edit1->Text.Length() + 1 ];
2)strcpy(sp,Edit1->Text.c_srt());中有两个字母你写错顺序了。应该是str而不是srt。



给我加分吧! :)
swites 2003-09-11
  • 打赏
  • 举报
回复
答案是这样:

if(Edit1->Text != NULL)
{
char *sp = new char[Edit1->Text.Length()+1];
strcpy(sp,Edit1->Text.c_str());
recValue = StrToFloat(sp);
delete []sp;
}
实际上你还不如这样:
if(Edit1->Text != NULL)
recValue=StrToFloat(Edit1-Text);
wide288 2003-09-11
  • 打赏
  • 举报
回复
if(Edit1->Text != NULL)
{
char *sp = new char[Edit1->Length()+1];
strcpy(sp,Edit1->Text.c_srt());
recValue = atof(sp);
delete[] sp;
}
还是有错误,recValue 是我定义的一个double 型的全局变量。
这是 binbin 的答案,没有通过。
出错信息是:

'Length'is not a member of 'TEdit'
'c_str'is not a member of 'AnsiString'

----------------------------------------------------------------
如果用netsys2 的方法,就出现:
[Linker Error] Unresolved external '__fastcall TFormMain::Button1Click(System::TObject *)' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\RQ200\FIRST.OBJ
[Linker Error] Unresolved external '_recValue' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\RQ200\SECOND.OBJ
[Linker Error] Unresolved external '__fastcall TFormMain::FormCreate(System::TObject *)' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\RQ200\FIRST.OBJ
[Linker Error] Unresolved external '__fastcall TFormMain::N4Click(System::TObject *)' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\RQ200\FIRST.OBJ

太可怕了。:)

wide288 2003-09-11
  • 打赏
  • 举报
回复
是吗,那我就不对了。没有好好的搜就问。
谢谢三位了。
binbin 2003-09-11
  • 打赏
  • 举报
回复
我发现这是问的最频繁的几个问题之一了!
char* sp=new char[Edit1->Text.Length()+1];
strcpy(sp,Edit1->Text.c_str());
//...用吧,用吧,用吧//

delete [] sp;//用完了???干掉!!!

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧