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
2 answers

How to copy streambuf to unsigned char array?

how can I copy data in streambuf to a unsigned char array? The code below have compiler errors: boost::asio::streambuf buf; std::ostream os(&buf); boost::archive::binary_oarchive oa(os); oa << m_data; // allocate space for the buffer unsigned char*…
venusisle
  • 113
  • 2
  • 10
0
votes
1 answer

How do I build a filtered_streambuf based on basic_streambuf?

I have a project that requires me to insert a filter into a stream so that outgoing data will be modified according to the filter. After some research, it seems that what I want to do is create a filtered_streambuf like this: template
swestrup
  • 4,079
  • 3
  • 22
  • 33
0
votes
1 answer

How to return streambuf pointer

I have wrote my own input streambuf, which should work with gzipped files. Here is its interface: class gzstreambuf : public std::streambuf { static const int bufferSize = 8192; public: gzstreambuf(); ~gzstreambuf(); int is_open() {…
Vardan Hovhannisyan
  • 1,101
  • 3
  • 17
  • 40
0
votes
2 answers

std::stringstream buffer manipulation

I am putting some data into a stream buf obtained from stringstream std::stringstream data; auto buf = data.rdbuf(); buf->sputn(XXX); What I want is to be able to put some dummy data into this buffer and then at a later time, once I have the…
Arun
  • 3,138
  • 4
  • 30
  • 41
0
votes
1 answer

preload cin with a string of commands

I'm testing functions that require several console commands before they can execute. Instead of having to type those commands every single time I want to test the functionality of a particular method, I want to be able to just paste a line or two of…
user2514676
  • 473
  • 2
  • 6
  • 18
0
votes
3 answers

Why don't inherit from ifstream

I want to create a custom input file stream which automatically strips comments and other garbage data. I came up with the following solution: class FileReader : public std::ifstream { public: explicit FileReader(const char* fName) { open(fName);…
ifnull
  • 239
  • 2
  • 6
0
votes
1 answer

Passing from ostringstream to istringstream and to file

I desperately try to write in a ostringstream and then transfert the datas in the istringstream of an other object or in a file. std::ostringstream oss; oss << "Hello World"; For the first purpose, I try this…
fcaillaud
  • 31
  • 7
0
votes
1 answer

How does the buffer know how many characters to transfer from the external file during a flush operation?

Say I have an input operation: file >> x; If the internal buffer of file is empty underflow() will be called to import characters from the external device to the internal buffer of file. It is implementation-defined if the buffer will be partially…
David G
  • 94,763
  • 41
  • 167
  • 253
0
votes
1 answer

Implementation-defined synchronization of file streams - Why?

What was the rationale behind making synchronization of input file streams implementation-specific. Doesn't it seem obvious that the stream will fill its buffer (partially or wholly) with content from the external device? It says in Standard C++…
David G
  • 94,763
  • 41
  • 167
  • 253
0
votes
1 answer

Limit std::filebuf to file inside (archive) file

I am currently implementing a custom std::filebuf which reads files from uncompressed .zip archives. For each file in the archive I have the offset into the archive file and the size. Now I want to limit the filebuf to the interval [offset,…
Marius
  • 2,234
  • 16
  • 18
0
votes
0 answers

What the biggest size of output that std::codecvt::unshift() can need?

I am working on a custom file streambuf. Now, I want to flush on seek like fstream does. At this point I want to know how big the array for output of std::codecvt::unshift() should be? It seems to me that the size returned by…
wilx
  • 17,697
  • 6
  • 59
  • 114
0
votes
1 answer

boost iostreaming filter gets empty values

I tried to build a stream buffer for reading and writing char* using boost::iostreams: class MemBuf : public std::streambuf { public: MemBuf(char* s, std::size_t n) { setg(s, s, (char*)s+ n); } }; reading works fine: char…
Steve
  • 1,072
  • 11
  • 28
0
votes
1 answer

Reading boost::asio::streambuf yields bad data

I'm using boost::asio to create a TCP client. I'm testing it out by loading a web site. I can create a connection, read, have my callback fired, etc, no problem. However, at the of every packet, I'm finding this, or something like…
BTR
  • 4,880
  • 4
  • 24
  • 21
0
votes
0 answers

Which member of a streambuf class points to the actual buffer in memory?

This question is related to a prior question of mine. I used the code below to inspect the values in the streambuf object associated with cout. Using VS2010 IDE, I can see several members in this class. Could anyone point to me which one of these…
John Kalane
  • 1,163
  • 8
  • 17
-1
votes
1 answer

Writing to the stream buffer of a string stream overrides the previous data

What I want to do is to create string stream , and output stream, giving the buffer of string stream to output stream, so that it will output data to the string stream. Everything seems fine, but when I try to add data to buffer of the string…
Parviz Pirizade
  • 193
  • 2
  • 12
1 2 3
10
11