| | |
read & write Binary data
![]() |
•
•
•
•
Originally Posted by mhm_ra
i need to r write binary(hexadecimal) values into a text file then read this data and manipulate it as a number
“The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> void write(const char *filename) { std::ofstream file(filename); for ( int i = 100; i < 110; ++i ) { file << std::hex << i << '\n'; } } void read(const char *filename) { std::ifstream file(filename); int value; while ( file >> std::hex >> value ) { std::cout << "value = " << value << '\n'; } } int main() { static const char filename[] = "file.txt"; write(filename); read(filename); return 0; } /* my output value = 100 value = 101 value = 102 value = 103 value = 104 value = 105 value = 106 value = 107 value = 108 value = 109 */ /* file.txt 64 65 66 67 68 69 6a 6b 6c 6d */
“The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
![]() |
Similar Threads
- Login and retrieve user data from database (ASP.NET)
- image long binary data (ASP)
- Need help with Binary files and data types in VB6 (Visual Basic 4 / 5 / 6)
- Reading binary data from a file and writing it (Visual Basic 4 / 5 / 6)
- Binary data in app.config (C#)
Other Threads in the C++ Forum
- Previous Thread: read data from file
- Next Thread: Debug
Views: 16802 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count data delete desktop display dll dynamic encryption error exception file files fstream function functions game givemetehcodez graph graphics gui homework http iamthwee input int lazy linker list loop looping loops math matrix member memory multidimensional newbie number numbers object objects opengl output parameter pointer pointers problem program programming project python random read reading recursion recursive reference sort sorting spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual visualstudio win32 window windows winsock xml






