Questions tagged [filebuf]

`std::filebuf` template specification in C++

A filebuf object opens and manages a file pointer and serves as the stream buffer for fstream objects.

std::filebuf is actually a typedef for std::basic_filebuf<char, std::char_traits<char> >.

Wide-character file streams use std::wfilebuf which is a typedef for std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >.

Use this tag for questions about the stream buffer used by std::fstream, std::ifstream, std::ofstream and their wide-character equivalents. For questions about those classes themselves use , or . For more general questions use the or tags.

22 questions
0
votes
1 answer

Trying to derive from wfilebuf (filebuf) for logging

I'm basically trying to derive from wfilebuf so I can both output to a file and intercept the output to print it to the console/debug window as well as illustrated here: http://savingyoutime.wordpress.com/2009/04/21/ and/or here:…
0
votes
1 answer

Is it possible to pass the stringbuf's streambuf direct to the filebuf?

I'm working on function that manipulate a stringbuf and I need to keep this in a file. If I could pass the stringbuf directly to ofstream's filebuf that could be a huge advantage. I know that both use streambuf object than can I somehow replace the…
TheArchitect
  • 1,160
  • 4
  • 15
  • 26
0
votes
1 answer

What Does filebuf::sync Do on an Input Buffer?

I read here that, for an input buffer, filebuf::sync's: effects -if any- depend on the library implementation So my question then, is can anyone tell me what those effects are for gcc and Visual Studio?
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
4 answers

Standard functions and operations not working in class constructor

I am trying to make my first class with a constructor and it seems to be acting strangely. My class is derived from filebuf and for some reason, I am unable to open it in the constructor. I tried to add a cout statement for debugging, but the <<…
Michael
  • 1,263
  • 1
  • 12
  • 28
0
votes
1 answer

read and write from a filebuf using iostream

When allocating an iostream from a stringbuf, everything works well std::stringbuf fb; std::iostream fs(&fb); char i = 17, j = 42; fs.write(&i, 1); fs.write(&j, 1); char x, y; fs.read(&x, 1); fs.read(&y, 1); std::cout << (int) x << " " << (int) y <<…
Amxx
  • 3,020
  • 2
  • 24
  • 45
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

For file reading, when to use filebuf

I'm going to be doing random-access reading from a read-only binary file. The interface to ifstream seems simpler than filebuf; but is there any use-case where filebuf would give better performance? More details: I have a file of fixed-length…
1
2