[C/C++] std::memcpy Api Reference
반응형
std::memcpy
void* memcpy( void* dest, const void* src, std::size_t count ); Defined in header <cstring> |
Parameters
dest | - | pointer to the memory location to copy to |
src | - | pointer to the memory location to copy from |
count | - | number of bytes to copy |
Return value
dest
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> #include <cstdint> #include <cstring> int main() { // simple usage char source[] = "once upon a midnight dreary...", dest[4]; std::memcpy(dest, source, sizeof dest); for (char c : dest) std::cout << c << '\n'; // reinterpreting double d = 0.1; // std::int64_t n = *reinterpret_cast<std::int64_t*>(&d); // aliasing violation std::int64_t n; std::memcpy(&n, &d, sizeof d); // OK std::cout << std::hexfloat << d << " is " << std::hex << n << " as an std::int64_t\n"; } | cs |
Result
o n c e 0x1.999999999999ap-4 is 3fb999999999999a as an std::int64_t
Ref :
반응형
'IT > C, C++' 카테고리의 다른 글
[Jsoncpp] example : Basic, Read File / Write File (기본 사용법, 파일 읽고 쓰는 방법) (0) | 2017.01.15 |
---|---|
[JSONCPP] JsonCpp 다운로드 및 컴파일 방법 (0) | 2017.01.15 |
[C/C++] std::vector::erase() Reference (0) | 2016.10.21 |
[C/C++] vector api reference (0) | 2016.10.21 |
[C/C++] XOR 연산자 '^' (0) | 2016.10.20 |