Questions tagged [streambuf]

std::streambuf is the stream buffer type used by C++ iostreams.

C++ iostreams use a stream buffer to do any buffering of characters, manage the stream position and transport characters to/from an external device such as a file.

Use this tag for questions about std::streambuf, the wide-character equivalent std::wstreambuf, or the class template std::basic_streambuf. The tag might also be relevant.

152 questions
0
votes
1 answer

UART stream packetisation; stream or vector?

I am writing some code to interface an STM32H7 with a BM64 Bluetooth module over UART. The BM64 expects binary data in bytes; in general: 1. Start word (0xAA) 2-3. Payload length 4. Message ID 5-n. Payload n+1. Checksum My question…
0
votes
1 answer

C++ istreambuf_iterator template parameter

Based on this question: C++ streams confusion: istreambuf_iterator vs istream_iterator? on istreambuf_iterator, my understanding is that istreambuf_iterator is an iterator for raw input rather than formatted input. In that case, is it correct to…
Sean Ian
  • 177
  • 4
0
votes
3 answers

How does this one stream command read in an entire file in c++?

Given this: auto f = std::ifstream{file}; if (f) { std::stringstream stream; stream << f.rdbuf(); return stream.str(); } return std::string{}; I don't see why it works. I don't know what type f is, because it says auto, but apparently…
stu
  • 8,461
  • 18
  • 74
  • 112
0
votes
5 answers

compile problem C++

Hey guys. I need to compile some project. I installed Visual C++ 6.0 + Microsoft Platform SDK 2003 from there http://www.microsoft.com/downloads/en/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en#requirements I also added…
pwnu91
  • 3
  • 4
0
votes
1 answer

Extending std::cout

I want to extend the usage of std::cout to use my own console/cout wrapper class. Ideally I would have 2 ostreams, one for regular printing and one that appends a new line. std::ostream Write; Write << "Hello, I am " << 99 << " years old."; prints…
anon
  • 59
  • 6
0
votes
0 answers

std::streambuf for tcp socket doesn't send data

I trying to write buffered std::streambuf for socket. I already wrote unbuffered std::streambuf. I don't understand why buffered streambuf doesn't work. Socket::StreamBuf::StreamBuf(const IO &io, tcp::Socket *socket) : …
ark0f
  • 35
  • 5
0
votes
2 answers

Using streambuf when sending/getting struct

I'm working on boost::asio::streambuf and found out that I can send/get a struct using it, but when I send a struct I just can't get it as I have sent it. The documentation says that one should use commit() and consume(), but where should I use them…
Abdurasul1996
  • 51
  • 1
  • 8
0
votes
0 answers

Overriding ostream behavior for basic data types via it's streambuf

I would like to perform some specialized processing of the data written to a std::ostream as it is being written. Lets say (for simplicity's sake), every time any of the basic data types are injected to my ostream, I want a comma to follow the…
Matthew Busche
  • 551
  • 4
  • 12
0
votes
1 answer

ZeroCopyOutputStream into a streambuf

I would like to write a class that inherites from streambuf and adapts a ZeroCopyOutputStream (google/protobuf/io/) into a streambuf. any ideas?
user515766
  • 349
  • 2
  • 5
  • 7
0
votes
1 answer

Send the last line of cout to a window

In my application I have a console (which uses std::out) and a window (that has a function to show some text). What I'm looking for is a way to show the last line of cout in my window. I've read some articles about making a custom streambuf class or…
Timo
  • 9,269
  • 2
  • 28
  • 58
0
votes
1 answer

Problems with writing a custom streambuf for gzipped streams

I am implementing my own streambuf class for writing compressed output files. Here what it is look like. template class gzstreambufbase : public std::streambuf { protected: static const int bufferSize = 8192; public: …
Narek Atayan
  • 1,479
  • 13
  • 27
0
votes
3 answers

Query regarding overflow function of streambuf

Going thorugh overflow function documentation. I found overflow has following as return values. Return Value: A value different than EOF (or traits::eof() for other traits) signals success. If the function fails, either EOF (or traits::eof() for…
user258367
  • 3,247
  • 2
  • 18
  • 17
0
votes
1 answer

Customize streambuffer for C++ ostream

I am implementing my own streambuffer for output stream. Basically it is a vector-like streambuffer in which everytime the overflow function simply reallocates the buffer to two times larger. The sync function will write all data out to the device…
Jes
  • 2,614
  • 4
  • 25
  • 45
0
votes
0 answers

Reading from boost serial_port reads incorrect data every few readings

I'm placing a string in my stream buffer of the form of "000.3\r\n 000.3\r\n ...". Every few readings I catch a ".3\r\n 000.3\r\n ... Since, I'm only reading from the buffer once per frame those sudden jumps in value become noticeable when drawing…
ZeroPhase
  • 649
  • 4
  • 21
0
votes
1 answer

Custom streambuffer in std::ofstream

I know that in std::ostream, I can use a custom streambuf through either stating so in the constructor: std::ofstream temp; temp.open("file.txt", std::ios_base::in); std::ostream example(temp.rdbuf()); as well as by setting it afterwards (same…
user4912670