如何正确打印无符号字符向量的一部分
How to print a part of a vector of unsigned chars properly?
typedef unsigned char BYTE;
std::vector<BYTE> bytes = readFile(path.c_str());
假设我想在向量中从位置30打印到34。
i tried this:
unsigned char chars[4];
for (int i = 30; i < 34; i++)
{
chars[i-30] = bytes[i];
}
std::cout << chars << std::endl;
我得到一个奇怪的符号,就是这样。从30到34的字符向量包含x14, 。我尝试将字符转换为unsigned int,以及一些类似的东西。
如果你只写std::cout << chars << std::endl
,它当然会打印出奇怪的东西,因为chars是一个指针。它在它的地址和下面的位置打印这个值,直到它到达的值读到