zengine-old/engine/3rdparty/zlib/test/refl/tstring.h
2024-04-04 18:18:04 +08:00

23 lines
567 B
C++

#include <string>
#include <iomanip>
using std::string;
template<typename T>
void PrintHex(T& obj) {
auto size = sizeof(T);
std::cout << type_name<T>().View() << "<" << size <<"> " << " = 0x";
char* ptr = (char*)& obj;
for (int i = 0; i < size; i++) {
std::cout << std::hex << std::setw(2) << std::setfill('0') <<(int)*(ptr + i);
}
std::cout << "FF" << std::endl;
}
void TestString1() {
string hello = "abcdef";
int size = sizeof(string);
PrintHex(hello);
hello = "abcdefabcdefabcdefabcdef";
PrintHex(hello);
//hello.~basic_string();
PrintHex(size);
}