| | |
Reading Binary files via stdin
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Solved Threads: 0
Okay, I need to read in a binary file from stdin and stick it in an array. The file contains binary representations of floating point numbers. I need to make sure that my array is sized properly based on the number of elements. It is quite easy to do with if stream as follows
However, I need this to work with a simple redirection, such as
program < infile.bin
I just can't seem to get anything that works. I appreciate your help.
C++ Syntax (Toggle Plain Text)
ifstream file("infile.bin", ios::binary | ios::ate); // Since we are at the end, we can get the size //file.seekg(0,ifstream::end); long size = file.tellg(); cout << size; file.seekg(0, ios::beg); //Seek back to the beginning float* unsorted; //Size input and read the file into it unsorted = new float[size]; file.read((char*)unsorted, size); file.close(); // Change size so it is the number of floats instead of // the number of characters size = size / 4;
However, I need this to work with a simple redirection, such as
program < infile.bin
I just can't seem to get anything that works. I appreciate your help.
![]() |
Similar Threads
- Reading binary file without knowing file format (C)
- reading encrypted binary files in C (C)
- Reading Binary Files in VB (Visual Basic 4 / 5 / 6)
- Read Files From stdin (C++)
- Reading binary files (Python)
- Need help with Binary files and data types in VB6 (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: c++ homework
- Next Thread: classes in C++
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






