Code:#include <string> #include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() { ifstream fstr( "somefile.txt" ); int word; fstr >> hex; while( fstr >> word ) { cout << word << " "; } }
Code:#include <string> #include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() { ifstream fstr( "somefile.txt" ); int word; fstr >> hex; while( fstr >> word ) { cout << word << " "; } }
Well, here's the thing.... You can't store a variable in hex! It's just a number....i just need to store the hex in a var from a file
You can input a number in hex format, or display a number in hex, but in the computer's memory it's "just a number" (stored in binary, of course).
Depending on what you're doing, you might find a Hex Editor useful. A hex editor allows you to view any file in hex, and edit the bytes. I use a hex editor called XVI32 (FREE !!!!).
Most hex editors will also show the ASCII characters for any bytes that fall in the "ASCII range". Of course, the hex editor actually has no idea if a value of 65 (41 hex) represents the value 65 or the character 'A'.
Open your file in binary mode. In binary node, you can read-in the file as numbers. The term binary is a little misleading.... I consider it the "raw mode"...i know how to read a regular text file but not hexidecimal.
Although the text mode is the default, it's a special case. Most file I/O is done in binary mode.
Last edited by DougDbug; 05-05-2006 at 04:07 PM.