   C++ Text Parsing
  Hi I'm working on building my own 3dloader for my projects. I want to load in a text file that 3dMax exports (.ase). So what I want to do is to store the 3 coordinates (x,y,z) into a vector (I have a vector class that I made) and each set of coordinates I'm gonna store in a list. So my only question is how to extract the proper info out of the text file and store them into my variables.And this is what the variable looks like that I want to store everything invector<CVector> m_vVerticies;heres an example of something 3dmax output in this .ase file*MESH_VERTEX    0-1.01590.54400.3233*MESH_VERTEX    11.18180.56590.3823*MESH_VERTEX    2-1.01590.5440-0.7235*MESH_VERTEX    31.18180.5659-0.7494*MESH_VERTEX    4-1.0159-0.5440-0.7235*MESH_VERTEX    51.1818-0.5659-0.7494*MESH_VERTEX    6-1.0159-0.54400.3233*MESH_VERTEX    71.1818-0.56590.3823*MESH_VERTEX    82.8143-0.55010.3559*MESH_VERTEX    92.81430.55010.3559*MESH_VERTEX   102.8143-0.5501-0.7444*MESH_VERTEX   112.81430.5501-0.7444*MESH_VERTEX   124.1005-0.37470.1423*MESH_VERTEX   134.10050.37470.1423*MESH_VERTEX   144.1005-0.3747-0.6070*MESH_VERTEX   154.10050.3747-0.6070*MESH_VERTEX   16-4.1701-0.35620.0344*MESH_VERTEX   17-4.17010.35620.0344*MESH_VERTEX   18-4.17010.3562-0.5525*MESH_VERTEX   19-4.1701-0.3562-0.5525*MESH_VERTEX   200.29000.56000.3772*MESH_VERTEX   210.29000.5633-0.7463*MESH_VERTEX   220.2900-0.5633-0.7463*MESH_VERTEX   230.2900-0.56000.3772*MESH_VERTEX   24-1.01590.7465-0.2001*MESH_VERTEX   251.18180.7764-0.1836*MESH_VERTEX   26-1.0159-0.0000-0.9182*MESH_VERTEX   271.1818-0.0000-0.9600*MESH_VERTEX   28-1.0159-0.7465-0.2001*MESH_VERTEX   291.1818-0.7764-0.1836*MESH_VERTEX   30-1.00680.00000.5186*MESH_VERTEX   311.17660.00000.5928*MESH_VERTEX   321.9941-0.56400.3791*MESH_VERTEX   331.99410.56400.3791*MESH_VERTEX   342.81430.00000.5606*MESH_VERTEX   351.9941-0.5640-0.7488*MESH_VERTEX   362.8143-0.7548-0.1942*MESH_VERTEX   371.99410.5640-0.7488*MESH_VERTEX   382.8143-0.0000-0.9491*MESH_VERTEX   392.81430.7548-0.1942*MESH_VERTEX   403.6131-0.50020.2848*MESH_VERTEX   413.61310.50020.2848*MESH_VERTEX   424.20400.00000.2172*MESH_VERTEX   433.6131-0.5002-0.7156*MESH_VERTEX   444.2040-0.4535-0.2362*MESH_VERTEX   453.61310.5002-0.7156*MESH_VERTEX   464.2040-0.0000-0.6897*MESH_VERTEX   474.20400.4535-0.2362*MESH_VERTEX   48-2.8559-0.48360.1944*MESH_VERTEX   49-2.85590.48360.1944*MESH_VERTEX   50-4.45540.00000.0819*MESH_VERTEX   51-2.85590.4836-0.6600*MESH_VERTEX   52-4.45540.4312-0.2649*MESH_VERTEX   53-2.8559-0.4836-0.6600*MESH_VERTEX   54-4.4554-0.0000-0.6116*MESH_VERTEX   55-4.4554-0.4312-0.2649*MESH_VERTEX   560.17621.0239-0.1679*MESH_VERTEX   570.2900-0.0000-0.9550*MESH_VERTEX   580.1762-1.0239-0.1679*MESH_VERTEX   59-5.0227-0.0000-0.2765*MESH_VERTEX   601.99410.00000.5890*MESH_VERTEX   611.9941-0.7738-0.1849*MESH_VERTEX   621.9941-0.0000-0.9587*MESH_VERTEX   631.99410.7738-0.1849*MESH_VERTEX   643.62300.00000.4700*MESH_VERTEX   653.6230-0.6858-0.2158*MESH_VERTEX   663.6230-0.0000-0.9015*MESH_VERTEX   673.62300.6858-0.2158*MESH_VERTEX   68-2.88380.00000.3503*MESH_VERTEX   69-2.88380.6625-0.2334*MESH_VERTEX   70-2.8838-0.0000-0.8170*MESH_VERTEX   71-2.8838-0.6625-0.2334*MESH_VERTEX   72-0.28670.55510.3587*MESH_VERTEX   730.76320.56400.3826*MESH_VERTEX   74-0.28670.5568-0.7386*MESH_VERTEX   750.76320.5656-0.7491*MESH_VERTEX   76-0.2867-0.5568-0.7386*MESH_VERTEX   770.7632-0.5656-0.7491*MESH_VERTEX   78-0.2867-0.55510.3587*MESH_VERTEX   790.7632-0.56400.3826*MESH_VERTEX   80-1.01590.69590.0860*MESH_VERTEX   81-1.01590.6959-0.4861*MESH_VERTEX   821.18180.72380.1257*MESH_VERTEX   831.18180.7238-0.4928*MESH_VERTEX   84-1.01590.2973-0.8696*MESH_VERTEX   85-1.0159-0.2973-0.8696*MESH_VERTEX   861.18180.3092-0.9073*MESH_VERTEX   871.1818-0.3092-0.9073*MESH_VERTEX   88-1.0159-0.6959-0.4861*MESH_VERTEX   89-1.0159-0.69590.0860*MESH_VERTEX   901.1818-0.7238-0.4928[Edited by - kubapl on June 5, 2008 3:44:12 PM]
  Well it depends on how much variation you have to expect in the text file...but for what you posted you could just use ifstream to pull out the strings and numbers.  It will convert to int/float for you, and will ignore the white space.  But again I don't know the full spec of that file format, so I don't know if it will be sufficient for everything.  For what you've posted it looks like you could just do this, though:ifstream fileReader(fileName.c_str());string key;while (!fileReader.eof()){    fileReader >> key;    if (key == "*MESH_VERTEX")    {   int index;   CVector vertex;   fileReader >> index;   fileReader >> vertex.x;   fileReader >> vertex.y;   fileReader >> vertex.z;   m_vVertices.push_back(vertex);    }    else if (...)    {   ...    }};  You could also implement operator>>() for your vector class. The resulting code would look much like MJP's example (and would be functionally equivalent), but it would be a bit more clear and concise.Also, what does the 'C' in 'CVector' stand for?   ;Quote:Original post by jykAlso, what does the 'C' in 'CVector' stand for?hehe, another one that thinks you need to be clear about the object being a class :D;Quote:Original post by jykAlso, what does the 'C' in 'CVector' stand for?The C tells me its a Class :)By the way this work beutifuly! I just modified it that instead of creating a vector in the function I just use a data member from the class the function sits in.Umm moving on my object isnt rendering for some reason if anyone know why please tell me what I'm doing wrong. . .Here is my rendering function. This is OpenGL C++void CObject::Render(){vector< CVector* >::iterator itVertices = m_lstVertices.begin();m_nDisplayList = NULL;m_nDisplayList = glGenLists( 1 );glNewList( m_nDisplayList, GL_COMPILE );glPushMatrix();float fAngle = m_vOrientation.fy * 180.0f / 3.14159f;fAngle += 90;glTranslatef( m_vLocation.fx, m_vLocation.fy, m_vLocation.fz );glRotatef( fAngle, 0.0f, 1.0f, 0.0f );glBegin( GL_QUAD_STRIP );glColor3f( 0.54, 0.54, 0.54 );while( itVertices != m_lstVertices.end() ){glVertex3f( (*itVertices)->fx, (*itVertices)->fy, (*itVertices)->fz );++itVertices;}glEnd();glPopMatrix();glEndList();};Quote:The C tells me its a Class :)Ok. Does that mean that if it didn't have a 'C' in front of it you'd think it was something else? And if so, what?   ;  No its just a nameing convension that my teacher for c++ taut us so you can remember what variable are of what type. For example if I'm making an integer I'd do something like this int nNumber or if I'm doing a float, I'd do float fNumber. Data members inside a class I add a m_ in front so for example float m_fAngle.   ;Quote:Original post by kubaplNo its just a nameing convension that my teacher for c++ taut us so you can remember what variable are of what type.I tagged 'CAR' in big pink letters on my car, just so I can remember what it is. I also tagged 'GIRLFRIEND' on my girlfriend when she was sleeping, in case I forgot who she was.Name conventions usually serve a purpose if they are useful.Starting class names with a C does not provide any useful information. In every single case where it matters whether something is a class or not, the information will be readily available from the syntax of your code. Hence, jyk's question: what do you need this information for?Adding type information to variable names is usually a sign that the variable name is not good enough. When you write that additional n, you indicate that the variable is an integer. However, is that integer a count ? A size ? An index ? book_count, array_size or next_index all carry the type information that the variable is an integer, and don't need the additional type information.Member variables can be easily identified in many situations. When accessing them as members (object.member), inside initializer lists, or even inside very small functions (accessors), it is obvious that the accessed variables are members, and thus an initial prefix serves no purpose. And, in the cases where an ambiguity could happen (for instance, when a function parameter has the same name as the member variable), there is a standard prefix which can be used (this->member), and which was created for this very purpose. Thus, why are you reinventing the wheel instead of using the language feature?This is not really dangerous. It will just make your variable names harder to read and clash with most modern naming conventions (it's been a few years now that most major developers have stopped using this one).;Quote:Original post by kubaplNo its just a nameing convension that my teacher for c++ taut us so you can remember what variable are of what type. For example if I'm making an integer I'd do something like this int nNumber or if I'm doing a float, I'd do float fNumber. Data members inside a class I add a m_ in front so for example float m_fAngle.It's just Hungarian notation, something that became really big due to Microsoft's heavy emphasis of it in both the Windows API and MFC.  Lately it's been pretty much phased out, as the tools and languages in use are generally capable of telling us this sort of information without the programming having to manually embed it in the actual variable names and type names. I'm sure there are plenty of people who still use it, mostly because they work on older projects that have always used this convention (I happen to be one of those people).;Quote:Original post by jykQuote:The C tells me its a Class :)Ok. Does that mean that if it didn't have a 'C' in front of it you'd think it was something else? And if so, what?It makes sense when using interfaces in your code, i.e. class abc named CAbc and interface def named IDef.   