Why ofBuffer's getFirstLine() and getNextLine() are deprecated?

Hi, I’m using OF 0.9.0 the latest nightly build, but I found that a lot of ofBuffer’s methods are deprecated.

I wanted to use ofBuffer to load a text file, then read the content line by line.

Is there any other way to do this without using getFirstLine(), getNextLine() and isLastLine()?

1 Like

That functionality was replaced by standard C++ iterators, which makes them very easy to use with c++11 lambdas, iterators, etc.

ofBuffer file = ofBufferFromFile("mytext.txt");

ofBuffer::Lines lines = file.getLines();

for (const std::string& line : lines)
{
    std::cout << "LINE: " << line << std::endl;
}
3 Likes
ofBuffer file = ofBufferFromFile("mytext.txt");
ofBuffer::Lines lines = file.getLines();
ofBuffer::Line iter = lines.begin();

while (iter != lines.end())
{
    cout << "LINE: " << (*iter) << endl;
    ++iter;
}

etc.

3 Likes

Thank you very much!!

1 Like