Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.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++ 将无符号字符读入字符串_C++_Strcmp_Unsigned Char_Memcmp - Fatal编程技术网

C++ 将无符号字符读入字符串

C++ 将无符号字符读入字符串,c++,strcmp,unsigned-char,memcmp,C++,Strcmp,Unsigned Char,Memcmp,我有一个未签名字符数组: unsigned char buffer[BUFFER_SIZE]; 我想将该数组中的前N个无符号字符读入一个字符串,但是在查看strncpy()之后,它似乎只接受指向有符号字符的指针 我是否应该查看memcpy()?strcmp和memcmp比较数据,它们不会复制数据 无论如何,只要转换到char*并使用任何有意义的stdlib函数即可。不确定确切的语法,但如果可能,您应该使用: reinterpret_cast<char *>(buffer[i]);

我有一个未签名字符数组:

unsigned char buffer[BUFFER_SIZE];
我想将该数组中的前N个无符号字符读入一个字符串,但是在查看
strncpy()
之后,它似乎只接受指向有符号字符的指针


我是否应该查看
memcpy()

strcmp
memcmp
比较数据,它们不会复制数据


无论如何,只要转换到
char*
并使用任何有意义的stdlib函数即可。

不确定确切的语法,但如果可能,您应该使用:

reinterpret_cast<char *>(buffer[i]);
reinterpret_cast(缓冲区[i]);
另见:


< P>如果用字符串表示一个字符数组,C++中最简单的方法就是使用STD::拷贝,不需要任何东西:

unsigned char buffer[BUFFER_SIZE];
char dest[BUFFER_SIZE]

std::copy( buffer, buffer + N, dest );
如果您指的是std::string,只需使用迭代器样式的构造函数:

std::string dest( buffer, buffer + N );

缓冲区的格式是什么?全部是满的还是一半是空的?所有值是否具有相同的大小?你试过什么?@PaperBirdMaster-坏评论人。对我来说没有意义。这个问题很简单,不言自明。