Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::iostreams : equivalent of std::getline() in boost
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-22 14:14:06


AMDG

vandamme wrote:
> I want to use boost to read a text file like this :
>
> boost::iostreams::file_source file(filename.c_str());
>
> But, when I want to get each single line with getline(), it doesn't compile
> :
>
> while (std::getline(file, line)) { ...} // COMPILATION ERROR
>
> What's the equivalent in boost for std::getline() ?
>

You can use boost::iostreams::stream.

#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/stream.hpp>
#include <istream>

int main() {
    std::string filename("test");
    boost::iostreams::stream<boost::iostreams::file_source>
file(filename.c_str());
    std::string line;
    while (std::getline(file, line)) { }
}

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net