
-----------------------------------
wtd
Sat Apr 09, 2005 12:52 am

[C++] Multiple Inheritance and the STL
-----------------------------------
The goal

So, let's build a class which allows for the construction of simple HTML tags.  Now, we'll be doing a lot of string concatenation, so we want something more efficient that constantly creating a lot of extra std::string objects.  Fortunately the STL provides just such a thing in std::stringstream.

We'll only be putting things into a stringstream, so we can use std::ostringstream.  We'll also want a way to keep track of which tag we're in, so a std::stack is also going to be needed.

First try

Let's take a first stab at it.

#include 
#include 
#include 
#include 

using namespace std;

class tag_stream
{
   private:
      ostringstream stream;
      stack current_tag;
   public:
      void start_tag(string tag_name);
      void end_tag();

      string str() const;

      template 
      friend tag_stream& operator