Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: help with implementation of strspn( ) Pin
David Crow1-May-09 16:11
David Crow1-May-09 16:11 
AnswerRe: help with implementation of strspn( ) Pin
Stuart Dootson1-May-09 16:15
professionalStuart Dootson1-May-09 16:15 
Questionwhat is wrong with this code snippet - memset() implementation Pin
kaku_lala1-May-09 15:42
kaku_lala1-May-09 15:42 
AnswerRe: what is wrong with this code snippet - memset() implementation Pin
Stuart Dootson1-May-09 16:11
professionalStuart Dootson1-May-09 16:11 
AnswerRe: what is wrong with this code snippet - memset() implementation Pin
David Crow1-May-09 16:15
David Crow1-May-09 16:15 
AnswerRe: what is wrong with this code snippet - memset() implementation Pin
Joe Woodbury1-May-09 19:32
professionalJoe Woodbury1-May-09 19:32 
QuestionOperator overloading and chaning streaming operators Pin
squall231-May-09 14:04
squall231-May-09 14:04 
AnswerRe: Operator overloading and chaning streaming operators Pin
Stuart Dootson1-May-09 16:06
professionalStuart Dootson1-May-09 16:06 
Your best bet would probably be to derive LogClass from std::ostream - that way you can make use of all the operator<< definitions in the std namespace. Look at how std::ostringstream works - it derives from ostream and passes a string buffer (as opposed to the file buffer that std::cout would pass) into the ostream base class when constructed.

To summarise, you'd have something like this:

template<class Elem, class Traits = std::char_traits<Elem> >
class basic_log_buffer : public std::basic_streambuf<Elem, Traits>
{
   // Override the necessary protected virtual functions
};

template<class Elem, class Traits = std::char_traits<Elem> >
class basic_log_stream : public std::basic_ostream<Elem, Traits>
{
public:
   LogStream() : basic_ostream(&my_buffer), my_buffer(whatever) {}
   // Override the necessary functions
private:
   basic_log_buffer<Elem, Traits> my_buffer;
};


This page[^] has an example of deriving new buffer and stream classes. This link[^], to page 209 of Angelika Krafter and Klaus Kreft's book about C++ streams is also of interest - in fact, their book tells you all you want to know about C++ streams and more besides - it's very good. Unfortunately, the Google Book Search link is to a preview of the book - pages are left out every so often, usually the important ones.

To output your log object, you then just need to provide an implementation of operator<< taking your log class.

Here's an operator<< I just wrote for std::ostringstream:

namespace std
{
   ostream& operator<<(ostream& os, ostringstream& oss)
   {
      os << oss.str();
      // Clear the stringstream as we've used its content
      oss.str("");
      return os;
   }
}


This will write the ostringstream's contents to the specified ostream when used like so:

std::ostringstream oss;
oss << "Hello";
std::cout << oss << std::endl;


Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Operator overloading and chaning streaming operators Pin
squall232-May-09 1:41
squall232-May-09 1:41 
QuestionHow do I debug a release build? Pin
bulg1-May-09 10:42
bulg1-May-09 10:42 
AnswerRe: How do I debug a release build? Pin
Rolf Kristensen1-May-09 11:31
Rolf Kristensen1-May-09 11:31 
GeneralRe: How do I debug a release build? Pin
bulg1-May-09 13:51
bulg1-May-09 13:51 
GeneralRe: How do I debug a release build? Pin
Stuart Dootson1-May-09 15:22
professionalStuart Dootson1-May-09 15:22 
QuestionPutting out plain text Pin
BobInNJ1-May-09 8:09
BobInNJ1-May-09 8:09 
QuestionRe: Putting out plain text Pin
David Crow1-May-09 8:19
David Crow1-May-09 8:19 
AnswerRe: Putting out plain text Pin
BobInNJ1-May-09 10:00
BobInNJ1-May-09 10:00 
GeneralRe: Putting out plain text Pin
David Crow1-May-09 10:03
David Crow1-May-09 10:03 
QuestionRe: Putting out plain text Pin
Maximilien1-May-09 8:24
Maximilien1-May-09 8:24 
AnswerRe: Putting out plain text Pin
Chris Losinger1-May-09 9:07
professionalChris Losinger1-May-09 9:07 
GeneralRe: Putting out plain text Pin
BobInNJ2-May-09 4:41
BobInNJ2-May-09 4:41 
Questionshow the picture in the same window of MFC insted of showing in new window Pin
trinhminhson1-May-09 8:00
trinhminhson1-May-09 8:00 
Questionurgent please help basic c Pin
biggiant220001-May-09 6:09
biggiant220001-May-09 6:09 
AnswerRe: urgent please help basic c Pin
biggiant220001-May-09 6:19
biggiant220001-May-09 6:19 
AnswerRe: urgent please help basic c Pin
Chris Losinger1-May-09 6:32
professionalChris Losinger1-May-09 6:32 
AnswerRe: urgent please help basic c Pin
David Crow1-May-09 8:20
David Crow1-May-09 8:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.