Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.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
can c++;tcpserver是否接收未签名字符? 目前我有一个C TCP-Cclipse和一个C++ TCPserver,但是我只能从服务器端的流读取字符,这样所有的数据都会被转换成字符。由于C++ char是一个带符号的8位整数,而C客户端只能发送字节,它是无符号的8位整数,所以客户端发送的所有数据>=128都不能在服务器端正确接收。 例如: char[]textChars=text.tocharray(); 字节[]textBytes=新字节[textChars.Length*2]; 字节低; 字节高; UInt16电流; for(int i=0;i_C++_Tcp - Fatal编程技术网

can c++;tcpserver是否接收未签名字符? 目前我有一个C TCP-Cclipse和一个C++ TCPserver,但是我只能从服务器端的流读取字符,这样所有的数据都会被转换成字符。由于C++ char是一个带符号的8位整数,而C客户端只能发送字节,它是无符号的8位整数,所以客户端发送的所有数据>=128都不能在服务器端正确接收。 例如: char[]textChars=text.tocharray(); 字节[]textBytes=新字节[textChars.Length*2]; 字节低; 字节高; UInt16电流; for(int i=0;i

can c++;tcpserver是否接收未签名字符? 目前我有一个C TCP-Cclipse和一个C++ TCPserver,但是我只能从服务器端的流读取字符,这样所有的数据都会被转换成字符。由于C++ char是一个带符号的8位整数,而C客户端只能发送字节,它是无符号的8位整数,所以客户端发送的所有数据>=128都不能在服务器端正确接收。 例如: char[]textChars=text.tocharray(); 字节[]textBytes=新字节[textChars.Length*2]; 字节低; 字节高; UInt16电流; for(int i=0;i,c++,tcp,C++,Tcp,这是在客户端,我将在服务器端收到的内容打印为签名int: 如果我发送一个ascii码为136的字符,它将变成2个字节:0136。但在服务器端,它打印0,-22。 那么有没有一种方法让C++流读无符号字符呢? 还是有别的办法解决这个问题? 谢谢你的帮助 通过TCP连接得到的只是原始数据,而选择如何解释它决定了它的外观 最简单的解决方案可能是在打印/使用以下内容之前将其强制转换: signed char val = -22; // emulate receipt of s

这是在客户端,我将在服务器端收到的内容打印为签名int: 如果我发送一个ascii码为136的字符,它将变成2个字节:0136。但在服务器端,它打印0,-22。 那么有没有一种方法让C++流读无符号字符呢? 还是有别的办法解决这个问题?
谢谢你的帮助

通过TCP连接得到的只是原始数据,而选择如何解释它决定了它的外观

最简单的解决方案可能是在打印/使用以下内容之前将其强制转换:

signed char val = -22;               // emulate receipt of signed char.
printf ("%d\n", (unsigned char)val); // cast to change interpretation.
你的密码坏了

char[] textChars = text.ToCharArray();
....
for (int i = 0; i < textChars.Length; i++)
{
    current = (UInt16)textChars[i];

这只能求值为0。

您可以将收到的字符按字节(无符号字符)重新转换为字节
char[] textChars = text.ToCharArray();
....
for (int i = 0; i < textChars.Length; i++)
{
    current = (UInt16)textChars[i];
    high = (byte)(current / 256);