std

Transferring the ownership of object from one unique_ptr to another unique_ptr in C++11?

邮差的信 提交于 2020-12-27 07:42:47
问题 In C++11 we can transfer the ownership of an object to another unique_ptr using std::move() . After the ownership transfer, the smart pointer that ceded the ownership becomes null and get() returns nullptr. std::unique_ptr<int> p1(new int(42)); std::unique_ptr<int> p2 = std::move(p1); // Transfer ownership What are the situations where this will be useful as it is transferring the ownership to another unique_ptr ? 回答1: The following situations involve transferring ownership from one unique

Convert binary file to hex notation

。_饼干妹妹 提交于 2020-12-08 05:15:12
问题 I would like to obtain this hex notation for a binary I enter in parameter: The output I obtain and what I want: This is the code I written, I don't have the good hex number (for the part after 5A) , what I am doing wrong ? How to convert properly the byte I read to hex ? Thanks. int main(int argc, char *argv[]) { std::string parameter = "The\\Path\\To\My\exe.exe"; ifstream::pos_type size; char * memblock; ifstream file(parametre, ios::in | ios::binary | ios::ate); if (file.is_open()) { size

Convert binary file to hex notation

旧街凉风 提交于 2020-12-08 05:08:40
问题 I would like to obtain this hex notation for a binary I enter in parameter: The output I obtain and what I want: This is the code I written, I don't have the good hex number (for the part after 5A) , what I am doing wrong ? How to convert properly the byte I read to hex ? Thanks. int main(int argc, char *argv[]) { std::string parameter = "The\\Path\\To\My\exe.exe"; ifstream::pos_type size; char * memblock; ifstream file(parametre, ios::in | ios::binary | ios::ate); if (file.is_open()) { size