How to read a file line by line?
Re: How to read a file line by line?
You can do something like this:
std::ifstream file("myfile.txt");
std::string line;
while (std::getline(file, line))
{
// ... do stuff with line
}
I don't know right now how this handles the different line-ending formats though (windows, linux, mac). Guess you'll have to experiment. (edit: checked stackoverflow and it says it doesn't handle that one well: https://stackoverflow.com/questions/139 ... characters)
Irrlicht loaders generally open the whole file as binary. And then parse it with their own functions (check character by character until a line-end is reached). See for example CObjMeshFilerLoader.cpp the function COBJMeshFileLoader::copyLine (not sure if that one is good code or not).
std::ifstream file("myfile.txt");
std::string line;
while (std::getline(file, line))
{
// ... do stuff with line
}
I don't know right now how this handles the different line-ending formats though (windows, linux, mac). Guess you'll have to experiment. (edit: checked stackoverflow and it says it doesn't handle that one well: https://stackoverflow.com/questions/139 ... characters)
Irrlicht loaders generally open the whole file as binary. And then parse it with their own functions (check character by character until a line-end is reached). See for example CObjMeshFilerLoader.cpp the function COBJMeshFileLoader::copyLine (not sure if that one is good code or not).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to read a file line by line?
Thanks, I'll consider that
Re: How to read a file line by line?
Hi again. I found a way to do it through core::string().split. It automatically filters empty lines and it also is easier to implement loops using this method.