Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
当给定一个无符号字符数组时,ofstream会打印额外的字节,但仅在释放模式下 我正在编写一个C++类,向PDF添加数字签名,使用OpenSSL生成一个Sh1哈希,然后将其打印到文件: unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((unsigned char *)temp.c_str(), temp.size(), hash); std::ofstream fout("resources/hash.out", std::ios::binary); fout << hash; fout.close(); unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((无符号字符*)临时c_str(),临时大小(),散列); std::ofstreamfout(“resources/hash.out”,std::ios::binary); fout_C++_Arrays_String_Output_Iostream - Fatal编程技术网

当给定一个无符号字符数组时,ofstream会打印额外的字节,但仅在释放模式下 我正在编写一个C++类,向PDF添加数字签名,使用OpenSSL生成一个Sh1哈希,然后将其打印到文件: unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((unsigned char *)temp.c_str(), temp.size(), hash); std::ofstream fout("resources/hash.out", std::ios::binary); fout << hash; fout.close(); unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((无符号字符*)临时c_str(),临时大小(),散列); std::ofstreamfout(“resources/hash.out”,std::ios::binary); fout

当给定一个无符号字符数组时,ofstream会打印额外的字节,但仅在释放模式下 我正在编写一个C++类,向PDF添加数字签名,使用OpenSSL生成一个Sh1哈希,然后将其打印到文件: unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((unsigned char *)temp.c_str(), temp.size(), hash); std::ofstream fout("resources/hash.out", std::ios::binary); fout << hash; fout.close(); unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((无符号字符*)临时c_str(),临时大小(),散列); std::ofstreamfout(“resources/hash.out”,std::ios::binary); fout,c++,arrays,string,output,iostream,C++,Arrays,String,Output,Iostream,有一个用于NUL终止字符串的流插入器,它是所选的 但您正试图输出一个包含任意字节的固定长度数组,这是完全不同的,导致UB 只需使用memberfunction,它就是为此而设计的。有一个用于NUL终止字符串的流插入器,它就是所选择的 但您正试图输出一个包含任意字节的固定长度数组,这是完全不同的,导致UB 只需使用memberfunction,它就是为此而设计的。您需要考虑到OpenSSL的SHA方法不会以null终止输出。正常的操作符需要考虑OpenSSL的SHA方法不会为null终止输出。正常

有一个用于NUL终止字符串的流插入器,它是所选的

但您正试图输出一个包含任意字节的固定长度数组,这是完全不同的,导致UB


只需使用memberfunction,它就是为此而设计的。

有一个用于NUL终止字符串的流插入器,它就是所选择的

但您正试图输出一个包含任意字节的固定长度数组,这是完全不同的,导致UB


只需使用memberfunction,它就是为此而设计的。

您需要考虑到OpenSSL的SHA方法不会以null终止输出。正常的
操作符需要考虑OpenSSL的SHA方法不会为null终止输出。正常的
运算符不
SHA1
null终止缓冲区?另请注意
temp.size()
不包括null终止符。这不是C,所以不要标记它C。
SHA1
null终止缓冲区吗?还请注意
temp.size()
不包括null终止符。这不是C,所以不要标记它C。
for (int i=0; i<SHA_DIGEST_LENGTH; ++i)
    fout.put(hash[i]);