| | |
kind of aggravating
Thread Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 11
Reputation:
Solved Threads: 0
I am trying to dump 2 longs, an array of floats and DWORDs, and an array of shorts into a file, USING BINARY out mode. Here is my code:
vertexs.h just has the declaration of the struct OURCUSTOMVERTEX.
HERE is the crap that it is putting in my file (obviously not writing in binary out mode because this is just text).
I am looking for suggestions to solve my problem. maybe i missed something in my code... maybe it is all wrong.... maybe i am a retard.... or maybe this is a small issue that can easily be solved with another set of eyes....
thanks for the help
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <fstream> #include ".\vertexs.h" using namespace std; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { OURCUSTOMVERTEX p_verts[5] = { (0.0f, 0.0f, 0.0f, 0xffffffff), (10.0f, 0.0f, 0.0f, 0xffffffff), (12.0f, 5.0f, 0.0f, 0xffffffff), (10.0f, 10.0f, 0.0f, 0xffffffff), (0.0f, 10.0f, 0.0f, 0xffffffff) }; short p_Indices[9] = { 1, 2, 3, 1, 3, 5, 3, 4, 5 }; long i_verts = 5; long i_inds = 9; ofstream f_DataFile; f_DataFile.open("chris.raw", ios_base::binary); f_DataFile<<i_verts; f_DataFile<<i_inds; for (int temp = 0; temp < i_verts; temp++) { f_DataFile<<p_verts[temp].x; f_DataFile<<p_verts[temp].y; f_DataFile<<p_verts[temp].z; f_DataFile<<p_verts[temp].color<<(int)0; } for (int temp2 = 0; temp2 < i_inds; temp2++) { f_DataFile<<p_Indices[temp2]; } if (f_DataFile.fail()) { return 1; } return 0; }
vertexs.h just has the declaration of the struct OURCUSTOMVERTEX.
HERE is the crap that it is putting in my file (obviously not writing in binary out mode because this is just text).
C++ Syntax (Toggle Plain Text)
594.29497e+0094.29497e+0094.29497e+009429496729504.29497e+0090000000000000000000123135345
I am looking for suggestions to solve my problem. maybe i missed something in my code... maybe it is all wrong.... maybe i am a retard.... or maybe this is a small issue that can easily be solved with another set of eyes....
thanks for the help
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> .. obviously not writing in binary out mode because this is just text
ios_base::binary only disables the control sequence translations ( for '\n', '\r' etc.) that take place during formatted input or output. to write raw binary data to a file, you will have to use unformatted output functions. eg. basic_ostream<>::write
ios_base::binary only disables the control sequence translations ( for '\n', '\r' etc.) that take place during formatted input or output. to write raw binary data to a file, you will have to use unformatted output functions. eg. basic_ostream<>::write
Yes, don't feel bad. This trips up a lot of people.
The << and >> are always for doing text output. If you know any C they are comparable to the printf() and scanf() functions. In other words, they always convert numbers to/from their string representations.
So, like vijayan121 said, you'll have to go to a raw output function:
Good luck.
The << and >> are always for doing text output. If you know any C they are comparable to the printf() and scanf() functions. In other words, they always convert numbers to/from their string representations.
So, like vijayan121 said, you'll have to go to a raw output function:
f_DataFile.write( reinterpret_cast<const char *>( &i_verts ), sizeof( i_verts ) );Good luck.
![]() |
Other Threads in the C++ Forum
- Previous Thread: arrays
- Next Thread: Overloaded Function Help
| Thread Tools | Search this Thread |
anyfile api array based binary bitmap c++ c++borland c/c++ char class classes code coding compile console conversion count csimilaritybetweentext delete deploy desktop developer development directshow dll download draw dynamic dynamiccharacterarray email encryption error file forms fstream function functions game gdi+ givemetehcodez gnu graph gui homeworkhelp homeworkhelper http iamthwee ibm ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node output packing parameter pointer problem program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video visualc++ visualizationtoolkit win32 windows winsock wordfrequency wxwidgets






