How do I use the VALUE of a variable to do things in my code?
<p>I'm trying to parse an HTML file for a C++ assignment. The assignment is demonstrating stacks; we're supposed to push to the stack every time we hit a tag, and then pop off when we find the corresponding closing tag.</p>

<p>The teacher obviously wants us to hard-code a set of tags to detect, like:</p>

<pre><code>// Declare some stacks
Stack html;
Stack div;
...

// When you find an open tag, push to the corresponding stack
if (tagcontents == "html") { html.push(); }
if (tagcontents == "div") { div.push(); }
...

// When you find a close tag, push to the corresponding stack
if (tagcontents == "/html") { html.pop(); }
if (tagcontents == "/div") { div.pop(); }
...
</code></pre>

<p>The obvious downside of this is that if I want to support <a href="http://www.w3schools.com/tags/default.asp" rel="nofollow">all of the tags available in HTML</a>, I can expect to do lots of redundant coding. The teacher obviously wants us to pick just a small subset of the available tags, and go off those, but I think that's <strong>lame</strong>. Since I'm lazy (and I firmly believe that all programmers should be), I'm trying to come up with a dynamic solution.</p>

<p>The idea is, whenever I encounter a new tag, create a stack for it. This would allow my program to support ANY tag, regardless of validity. I'm hitting an interesting theoretical problem, though, and I'm not even sure what to call it in order to research it. Namely, that I need to use the VALUE of a variable as part of my actual code. IE:</p>

<pre><code>if (no stack exists named "HTML") { create a stack named "HTML" }
</code></pre>

<p>In simplistic terms, how can I:</p>

<pre><code>tag = "html";
Stack tag;  // make a stack named HTML?
</code></pre>

<p>Or is there another way to do this? Any help would be greatly appreciated. If I can't figure this out, I'll probably just use a switch/case statement like a quitter.</p>
