实现简单的输入流 [英] implementing simple input stream
问题描述
我想写一个简单的 istream
对象,这将简单地转换另一个 istream
。
I want to write a simple istream
object, that would simply transform another istream
.
我想只实现 readline
(从原始流中读取一行,处理它,并返回处理过的行) ,并且有一些通用代码,在读
将使用我的读取行,缓存它,并提供所需的字节数作为输出。
I want to only implement readline
(which would read a line from the original stream, would process it, and return the processed line), and have some generic code that upon read
would use my read line, cache it, and give the required amount of bytes as output.
有没有类允许我这样做?
Is there any class that would allow me to do that?
例如
struct mystream : istreamByReadLine {
istream& s;
mystream(istream& _s):s(_s){}
virtual string getline() {
string line;
getline(s,line);
f(line);
return line;
}
}
class istreamByReadLine : istream {
... // implementing everything needed to be istream compatible, using my
... // getline() virtual method
}
推荐答案
您查看了提升。 iostreams 吗?它为你做了大部分的咕噜工作(可能不是为你的确切的用例,但一般C ++标准库流)。
Have you looked at boost.iostreams? It does most of the grunt work for you (possibly not for your exact use case, but for C++ standard library streams in general).
这篇关于实现简单的输入流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!