streambuf

compile problem C++

狂风中的少年 提交于 2019-12-11 23:30:10
问题 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 SDK paths under Tools->Options->Directories and moved them to top. But I am still getting this errors when compiling... c:\users\admin\downloads\microsoft visual c++ 6.0 standard edition\vc98\include\new(9) : fatal error C1083: Cannot open include

C++: std::istream read and its calls to std::streambuf underflow

会有一股神秘感。 提交于 2019-12-11 03:55:01
问题 the following code simply tests how often underflow is called when using std::istream read on an std::stringbuf . #include <iostream> #include <vector> #include <sstream> class TestStringBuf : public std::stringbuf { public: int_type underflow() { std::cout<<"TestStringBuf underflow"<<std::endl; return std::stringbuf::underflow(); } }; int main(int argc, const char * argv[]) { TestStringBuf buf; std::iostream stream(&buf); stream << "tesr"; std::vector<char> data(4); stream.read(&data[0], 4);

How can I read from memory just like from a file using wistream?

别等时光非礼了梦想. 提交于 2019-12-09 22:47:18
问题 In my previous question I asked how to read from a memory just as from a file. Because my whole file was in memory I wanted to read it similarly. I found answer to my question but actually I need to read lines as a wstring . With file I can do this: wifstream file; wstring line2; file.open("C:\\Users\\Mariusz\\Desktop\\zasoby.txt"); if(file.is_open()) { while(file.good()) { getline(file,line2); wcout << line2 << endl; } } file.close(); Even if the file is in ASCII. Right now I'm simply

Implementing std::basic_streambuf subclass for manipulating input

≯℡__Kan透↙ 提交于 2019-12-08 01:22:38
问题 I have a std::basic_streambuf subclass that causes all output to be written in uppercase, like this: class upper_streambuf : public std::streambuf { public: upper_streambuf(std::streambuf &real) : m_realBuffer(real) { } protected: virtual int overflow(int c) { int uc = std::toupper(c); m_realBuffer.sputc(uc); return uc; } private: std::streambuf &m_realBuffer; }; I use it like this for example (which seems to work OK): upper_streambuf buf(*std::cout.rdbuf()); std::ostream ucout(&buf); ucout <

What are 'aliased' stream buffers?

佐手、 提交于 2019-12-07 15:37:23
问题 What are 'aliased stream buffers`? I encountered the term in a comment on an answer of mine. 回答1: I've never heard the term before, but in the thread you cite, the person who used it also gave an example: two streams which use the same streambuf. Of course, just because two streams don't use the same streambuf, doesn't mean that data written to them doesn't ultimately end up in the same place; that they don't alias the same sink, if that is what is meant. There are filtering streambuf's,

istream::tellg() returns -1 when used with my custom streambuf class?

五迷三道 提交于 2019-12-07 05:46:35
问题 I'm trying to create an istream that reads directly from a raw memory buffer. I found a nice way to do this in another post on here: class membuf : public basic_streambuf<char> { public: membuf(char* p, size_t n) { setg(p, p, p + n); } }; Then I create my istream using this membuf : membuf mb(dataPointer, dataLength); istream reader(&mb); I then read using getline() and >> operators, and everything is wonderful. However, I can't seem to use seekg() to rewind back to the beginning of my buffer

What can go wrong if cout.rdbuf() is used to switch buffer and never set it back?

空扰寡人 提交于 2019-12-07 04:40:08
问题 The author presented this code under the title A bus error on my platform #include <fstream> #include <iostream> int main() { std::ofstream log("oops.log"); std::cout.rdbuf(log.rdbuf()); std::cout << "Oops!\n"; return 0; } The string "Oops!\n" is printed to the file "oops.log". The code doesn't restore cout's streambuf, but VS2010 didn't report a runtime error. 回答1: Since log and std::cout share a buffer, that buffer will probably be freed twice (once when log goes out of scope, then once

How do I implement seekg() for a custom istream/streambuf?

一个人想着一个人 提交于 2019-12-07 04:07:06
问题 I used to be a C++ expert a decade ago, but for the past 10 years I've been programming Java. I just started a C++ project that uses a small third-party XML parser. The XML parser accepts an STL istream. My XML data is coming from a Windows COM IStream. I thought I'd do the Right Thing and create an adapter to take the IStream data and present it to the XML parser through an istream. I followed the excellent tutorial at http://www.mr-edd.co.uk/blog/beginners_guide_streambuf and created a

Implementing std::basic_streambuf subclass for manipulating input

梦想的初衷 提交于 2019-12-06 10:25:38
I have a std::basic_streambuf subclass that causes all output to be written in uppercase, like this: class upper_streambuf : public std::streambuf { public: upper_streambuf(std::streambuf &real) : m_realBuffer(real) { } protected: virtual int overflow(int c) { int uc = std::toupper(c); m_realBuffer.sputc(uc); return uc; } private: std::streambuf &m_realBuffer; }; I use it like this for example (which seems to work OK): upper_streambuf buf(*std::cout.rdbuf()); std::ostream ucout(&buf); ucout << "Hello, world!" << std::endl; // prints "HELLO, WORLD!" What I want to achieve is the more-or-less

How to implement custom std::streambuf's seekoff()?

烈酒焚心 提交于 2019-12-06 04:37:18
问题 I have the following implementation based on e.g. this question and answer struct membuf : std::streambuf { membuf(char* begin, char* end) { this->setg(begin, begin, end); } protected: virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in) { std::istream::pos_type ret; if(dir == std::ios_base::cur) { this->gbump(off); } // something is missing here... } }; I would like to use it in my methods in the following way: char buffer[] =