Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;Borland char*和strcpy >代码> Stistabs/Cuff>是C++ Builder 的 TMemo_C++_C++builder_Strcpy - Fatal编程技术网

C++;Borland char*和strcpy >代码> Stistabs/Cuff>是C++ Builder 的 TMemo

C++;Borland char*和strcpy >代码> Stistabs/Cuff>是C++ Builder 的 TMemo,c++,c++builder,strcpy,C++,C++builder,Strcpy,为什么我会犯这个错误 [C++错误]emulator.cpp(59):E2034无法将'char**'转换为'char*' 完整解析器上下文 cpp(56):解析:void _fastcalltmain::Button1Click(TObject*) char-dum[32]; strcpy(dum,InstList->line->Text.c_str()); char-dum[32]; strcpy(dum,InstList->line->Text.c_str()); 是一个长度为32的数组,

为什么我会犯这个错误

[C++错误]emulator.cpp(59):E2034无法将'char**'转换为'char*' 完整解析器上下文 cpp(56):解析:void _fastcalltmain::Button1Click(TObject*)

char-dum[32]; strcpy(dum,InstList->line->Text.c_str()); char-dum[32]; strcpy(dum,InstList->line->Text.c_str()); 是一个长度为32的数组,每个元素是一个
char*
。我猜你是想写信

char *dum[32];
这是一个32字符的数组,然后您可以写入:

char dum[32];
当然,要确保
InstList->Lines->Text
不会太大而溢出缓冲区

当然,我不知道为什么你需要在C++程序中使用C字符串。 是一个长度为32的数组,每个元素是一个
char*
。我猜你是想写信

char *dum[32];
这是一个32字符的数组,然后您可以写入:

char dum[32];
当然,要确保
InstList->Lines->Text
不会太大而溢出缓冲区

当然,我不知道为什么你需要在C++程序中使用C字符串。

你也可以使用(很容易出现严重的安全问题,称为缓冲区溢出)< /p> 或者(更好,因为它可以处理任意长度的数据,而不容易出现称为缓冲区溢出的严重安全问题)

编辑-根据评论:

我假设您使用的是一个较旧的BCB版本,它仍然具有
解析功能
——如果这是在较新的版本上unicode解构,那么代码可能会导致“奇怪的结果”,因为unicode字符串每个字符占用多个字节(取决于编码等)。

您可以使用(容易出现称为缓冲区溢出的严重安全问题)

或者(更好,因为它可以处理任意长度的数据,而不容易出现称为缓冲区溢出的严重安全问题)

编辑-根据评论:


我假设您使用的是较旧的BCB版本,该版本仍然具有
AnsiString
-如果这是在较新的版本上
UnicodeString
,那么代码可能会导致“奇怪的结果”,因为unicode字符串每个字符占用多个字节(取决于编码等).

不要使用
char*
而是使用
String
std::String
,如果出于某种原因需要指向字符串的指针,只需从字符串对象获取该指针即可

// C style
// char *dum = malloc(strlen(InstList->Lines->Text.c_str())+1); 

// BCB style...
char *dum = malloc(InstList->Lines->Text.Length()+1);  

// BEWARE: AFTER any malloc you should check the pointer returned for being NULL

strcpy(dum,InstList->Lines->Text.c_str());

不要使用
char*
而是使用
String
std::String
,如果出于某种原因需要指向字符串的指针,只需从字符串对象获取该指针即可

// C style
// char *dum = malloc(strlen(InstList->Lines->Text.c_str())+1); 

// BCB style...
char *dum = malloc(InstList->Lines->Text.Length()+1);  

// BEWARE: AFTER any malloc you should check the pointer returned for being NULL

strcpy(dum,InstList->Lines->Text.c_str());

好点,但不需要使用<代码> StLLN < />代码,因为<代码> StReS> > >文本< /C>当然有长度属性。请注意C++的Builder语法。“DavidHeffernan上次使用C++ Builder是几年前……查阅它……根据代码,代码>文本<代码>是代码>系统::UnoDeSooSt/<代码>和You将写入
长度(系统::UnicodeString)从Delphi中,我假设C++ Builder是相同的。<代码>文本<代码>是从TMemo后面的Windows编辑控件的内容动态生成的。我可能会把它读入<代码>系统::UnoODeStords<代码>变量。人们只想知道C字符串是如何进入方程的。@ DavidHeffernan,你是正确的。R当前版本……但是例如C++ Builder 6(!)这是定义为
AnsiString
的吗…难以置信,但是v6仍然在使用…当我看到C字符串处理时,我想到了旧版本,否则这个代码就不行了…@DavidHeffernan检查了文档…
System::UnicodeString
将返回
wchar\t*
,这是
C\str()的结果错误代码OP发布的这篇文章似乎是一个旧版本,使用了<代码> ANSICONS/<代码>…好点,但不需要使用<代码> StLLN < /C> >,因为 StRepp-> Trime>文本肯定有长度属性。请注意C++ C++ Builder语法。请注意,DavidHeffernan上次使用C++Builder是SeVela。1年前…查了一下…根据文档,
Text
System::UnicodeString
你会写
Length(System::UnicodeString)从Delphi中,我假设C++ Builder是相同的。<代码>文本<代码>是从TMemo后面的Windows编辑控件的内容动态生成的。我可能会把它读入<代码>系统::UnoODeStords<代码>变量。人们只想知道C字符串是如何进入方程的。@ DavidHeffernan,你是正确的。R当前版本……但是例如C++ Builder 6(!)这是定义为
AnsiString
的吗…难以置信,但是v6仍然在使用…当我看到C字符串处理时,我想到了旧版本,否则这个代码就不行了…@DavidHeffernan检查了文档…
System::UnicodeString
将返回
wchar\t*
,这是
C\str()的结果
…鉴于OP发布的错误消息,这似乎是一个带有
AnsiString
…的旧版本。。。
// C style
// char *dum = malloc(strlen(InstList->Lines->Text.c_str())+1); 

// BCB style...
char *dum = malloc(InstList->Lines->Text.Length()+1);  

// BEWARE: AFTER any malloc you should check the pointer returned for being NULL

strcpy(dum,InstList->Lines->Text.c_str());
String myString = InstList->Lines->Text;
myString.c_str();