| | |
read & write Binary data
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
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
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
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 */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- 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)
- Login and retrieve user data from database (ASP.NET)
- Binary data in app.config (C#)
Other Threads in the C++ Forum
- Previous Thread: read data from file
- Next Thread: Debug
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






