| | |
post Trying to override streambuf to use with cout
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I'm trying to grab all the input sent to cout to modify and redirect it. I used the example from http://www.dreamincode.net/code/snippet2499.htm, which works fine using the following code:
The class overrides streambuf and simply XORs the input characters before sending them to the provided streambuf (in this case, a file). My problem occurs when I try setting cout's rdbuf() to filter:
This code causes a glibc "double free or corruption (!prev)" error. Could anyone tell me where I am going wrong? Perhaps I just don't understand the concepts properly?
Thanks very much.
I'm trying to grab all the input sent to cout to modify and redirect it. I used the example from http://www.dreamincode.net/code/snippet2499.htm, which works fine using the following code:
C++ Syntax (Toggle Plain Text)
std::ofstream file_sink("encrypted.bin", std::ios_base::binary | std::ios_base::out); basic_xor_filter<char> filter(*(file_sink.rdbuf()), 0x7F); std::ostream output_stream(&filter); output_stream << "Hello World" << std::endl; output_stream.flush();
The class overrides streambuf and simply XORs the input characters before sending them to the provided streambuf (in this case, a file). My problem occurs when I try setting cout's rdbuf() to filter:
C++ Syntax (Toggle Plain Text)
streambuf* s = &filter; cout.rdbuf( s ); cout << "Hello World\n";
This code causes a glibc "double free or corruption (!prev)" error. Could anyone tell me where I am going wrong? Perhaps I just don't understand the concepts properly?
Thanks very much.
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
C++ Syntax (Toggle Plain Text)
streambuf* s = &filter; streambuf* old = cout.rdbuf(s); cout << "Hello World" << endl; cout.flush(); cout.rdbuf(old);
How does your 'filter' look? Maybe more problems here!?
Last edited by jencas; Jan 12th, 2009 at 10:36 am.
If you are forced to reinvent the wheel at least try to invent a better one!
Please use code tags - Please mark solved threads as solved
Please use code tags - Please mark solved threads as solved
![]() |
Other Threads in the C++ Forum
- Previous Thread: Windows API tutorial??
- Next Thread: How to execute a program within another program?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





