so ive been messing round with c++ for about a year and i know ive got tons to learn and im planning on going to college for software development but as for now im a self taught programmer. With that said, please be patient with me.. im trying to write an OBJ loader for d3dx10. the way the file was written intimidated me a little so i wrote a function to organize it and make it easier to read through line by line. now im writing the function to read through the file, loading each line(x, y, z) into a d3dxvector3 vector and eventually load into a mesh but it says i dont have a null terminated string.. now i know that a string ends with a null so the pc knows thats the end of the string but when i stored it into a char * to stream through the string and break it down into x, y, and z i cant figure out how to add that null character.. i believe it would change my code drastically and i have no idea how else to do it... so thanks for the help in advance... also i have a second problem.. when i try to use the function it always throws an error to the file parameter and i dont understand the error so idk whats wrong:
I've no clue about what D3DXVECTOR3 is; assuming that it is some type can be constructed from three float values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// void PrepareOBJ(ifstream inputFile, ofstream outputFile)
// streams are not copyable, pass by reference
void PrepareOBJ( ifstream& inputFile, ofstream& outputFile )
{
// copy contents of input file to output file, replacing 'v' with '\n'
char c ;
while( inputFile.get(c) ) outputFile << ( c == 'v' ? '\n' : c ) ;
}
struct D3DXVECTOR3 { D3DXVECTOR3(float,float,float) ; /* ... */ };
// it doesn't make sense to pass the vector by value
void LoadOBJ( vector<D3DXVECTOR3>& Positions, ifstream& File )
{
float x = 0, y = 0, z = 0;
while( File >> x >> y >> z ) Positions.push_back( D3DXVECTOR3(x,y,z) ) ;
}
thank you for your help, but just for clarification, when i tried your prepare obj function it did nothing. mine was already working, but i dont understand how your function progressively makes its way through the file.. id like to understand your method just for learning purposes and yours is shorter. will get() continuously move to the next char in the file? i thought it would just get the first char.. unless maybe i gave it a position like using .at or something like it? (doesnt sound like a ? but it is lol) and secondly can you explain how:
while( File >> x >> y >> z ) Positions.push_back( D3DXVECTOR3(x,y,z) ) ;
will break this line into three variables??? " 2.675214 -2.638026 -1.912134"
i want it to read through each line.. load into a string, break into three variables(x, y, z) and store in a d3dxvector3.. btw you cant redefine the d3dxvector3 struct.. so instead of:
> will get() continuously move to the next char in the file?
Yes. Repeatedly calling get() will retrieve characters one by one till end of file.
> while( File >> x >> y >> z ) Positions.push_back( D3DXVECTOR3(x,y,z) ) ;
> will break this line into three variables??? " 2.675214 -2.638026 -1.912134"