Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
Embarcadero不能从';破坏';至';无符号字符*'; 我使用的是NavaCabro的C++ Builder XE/P> String command1 = "FREQ "; String command2 = " Mhz\n"; int index = Form1->ListBox1->ItemIndex; String full = command1.operator +=(IntToStr((index+2)*10)).operator +=(command2); TcpClient1->SendBuf((BYTE*)full,13,0);Sleep(30);_C++_String_Casting_C++builder_Unicode String - Fatal编程技术网

Embarcadero不能从';破坏';至';无符号字符*'; 我使用的是NavaCabro的C++ Builder XE/P> String command1 = "FREQ "; String command2 = " Mhz\n"; int index = Form1->ListBox1->ItemIndex; String full = command1.operator +=(IntToStr((index+2)*10)).operator +=(command2); TcpClient1->SendBuf((BYTE*)full,13,0);Sleep(30);

Embarcadero不能从';破坏';至';无符号字符*'; 我使用的是NavaCabro的C++ Builder XE/P> String command1 = "FREQ "; String command2 = " Mhz\n"; int index = Form1->ListBox1->ItemIndex; String full = command1.operator +=(IntToStr((index+2)*10)).operator +=(command2); TcpClient1->SendBuf((BYTE*)full,13,0);Sleep(30);,c++,string,casting,c++builder,unicode-string,C++,String,Casting,C++builder,Unicode String,在我收到的最后一条线上 E2031无法从“UnicodeString”转换为“unsigned char*” 我发送的是我的设备(接收器)的命令,其格式为(command,lenght\u of_command)。当我在计划文本中发送时,如 TcpClient1->SendBuf((BYTE*)"FREQ 330.5 MHz\n",15,0);Sleep(30); 一切都好。非常感谢您的帮助。我只想使用sprintf char command[999]; sprintf(command,

在我收到的最后一条线上 E2031无法从“UnicodeString”转换为“unsigned char*”

我发送的是我的设备(接收器)的命令,其格式为(command,lenght\u of_command)。当我在计划文本中发送时,如

TcpClient1->SendBuf((BYTE*)"FREQ 330.5 MHz\n",15,0);Sleep(30);

一切都好。非常感谢您的帮助。

我只想使用sprintf

char command[999];
sprintf(command, "FREQ %d MHz\n", (index+2)*10);
TcpClient1->SendBuf((BYTE*)command,strlen(command),0);
Sleep(30);

String
映射到XE中的
UnicodeString
。修复代码的最简单方法是改用
AnsiString
(并停止使用
+=
运算符,因为您没有正确使用它):

或者:

int index = Form1->ListBox1->ItemIndex;
AnsiString full;
full.sprintf("FREQ %d Mhz\n", (index+2)*10);
TcpClient1->SendBuf((BYTE*)full.c_str(),full.Length(),0);
Sleep(30);

您正在浪费超过900个永远不会被使用的字节。将数组的大小减小到实际需要的最小长度(最多21个),或者切换到
AnsiString
并使用其
sprint()方法。
int index = Form1->ListBox1->ItemIndex;
AnsiString full;
full.sprintf("FREQ %d Mhz\n", (index+2)*10);
TcpClient1->SendBuf((BYTE*)full.c_str(),full.Length(),0);
Sleep(30);