while(memcmp( line, " *MESH",5) != 0)
{
openfile.getline(line,255);
}
is this normal for c++ File I/O or am i missing something??? It seems easier to read in text files such as the ASE format in C and not in C++.
Any comments or advice would be appreciated.
Werdy666
c++ File I/O
i am having afew problems trying to read a text file into my program. I''m trying to read in an ase file, however using fstream''s getline, it is reading the tabbed spaces into my buffer.
Looking at acouple of ase loader examples has been no good cause they seem to only use C File I/O.
i did work it out eventually by actually just pressing tab in the compare string.
i personally have not used getline before, i just read in strings/numbers in one at a time...
specifically for the *mesh example...
it will automatically skip spaces, tabs and newlines, if u open it in txt mode that is.
specifically for the *mesh example...
string temp;...openfile >> temp;if (temp=="*MESH") {// do stuff...}
it will automatically skip spaces, tabs and newlines, if u open it in txt mode that is.
I think you are slightly confused ... when you call getline() you tell it what delimiter you want to use ... so if you have a file format where every line is 3 tab delimited columns and then an end of line ... you would think of your parser like this
obviously, I don''t know the ASE format, so I can''t give you specific code ... and the above will get more compilated, when the file has variable numbers of columns, etc ...
I''m mainly just trying to show how getline is meant to be used
// read in the entire filewhile(openfile) { // for each line in the file openfile.getline(column1,''\t''); // reads till first tab openfile.getline(column2,''\t''); // reads till second tab openfile.getline(column3,''\n''); // read till end of line }
obviously, I don''t know the ASE format, so I can''t give you specific code ... and the above will get more compilated, when the file has variable numbers of columns, etc ...
I''m mainly just trying to show how getline is meant to be used
I think you are slightly confused ... when you call getline() you tell it what delimiter you want to use ... so if you have a file format where every line is 3 tab delimited columns and then an end of line ... you would think of your parser like this
obviously, I don''t know the ASE format, so I can''t give you specific code ... and the above will get more compilated, when the file has variable numbers of columns, etc ...
I''m mainly just trying to show how getline is meant to be used
// read in the entire filewhile(openfile) { // for each line in the file openfile.getline(column1,''\t''); // reads till first tab openfile.getline(column2,''\t''); // reads till second tab openfile.getline(column3,''\n''); // read till end of line }
obviously, I don''t know the ASE format, so I can''t give you specific code ... and the above will get more compilated, when the file has variable numbers of columns, etc ...
I''m mainly just trying to show how getline is meant to be used
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement