#include #include using namespace std; int main(int argc, char * argv[]) { string fileName {"data.raw"}; if (argc > 1) { fileName = argv[1]; } ifstream inFile(fileName, ios::binary); cout << "Reading character by character" << endl; char letter; while(inFile) { inFile.read(reinterpret_cast(&letter),sizeof(letter)); cout << letter << " "; } cout << endl; inFile.clear(); inFile.seekg(0, ios::beg); cout << "Reading character by character as int" << endl; while(inFile) { inFile.read(reinterpret_cast(&letter),sizeof(letter)); cout << static_cast(letter) << " "; } cout << endl; inFile.clear(); inFile.seekg(0, ios::beg); cout << "Reading short by short" << endl; short shortVal; cout << hex; while(inFile) { inFile.read(reinterpret_cast(&shortVal),sizeof(shortVal)); cout << shortVal << " "; } cout << endl; inFile.clear(); inFile.seekg(0, ios::beg); cout << endl << endl; cout << "byte by byte as short MSB - LSB" << endl; char byte; short last; while(inFile) { inFile.read(reinterpret_cast(&byte),sizeof(byte)); last = static_cast(byte) << 8; inFile.read(reinterpret_cast(&byte),sizeof(byte)); last += static_cast(byte); cout << last << " "; } cout << endl; inFile.clear(); inFile.seekg(0, ios::beg); cout << "byte by byte as short LSB - MSB" << endl; while(inFile) { inFile.read(reinterpret_cast(&byte),sizeof(byte)); last = static_cast(byte); inFile.read(reinterpret_cast(&byte),sizeof(byte)); last += (static_cast(byte) << 8); cout << last << " "; } cout << endl; inFile.close(); return 0; }