stack declaration segmentation fault
<p>just my practice. 
//read a sentence with "()" in it and replace everything in () with "(deleted)". </p>

<p>1)read the sentence to a vector. </p>

<p>2) stack the vector into a stack >.<br>
3) find the positions of both "("
   and ")"<br>
4) remove the elements and replace with "(deleted)" in
   vector<br>
5) output the vector.</p>

<p>ie. input "this is (a) duck", output should be "this is (deleted) duck". thanks in advance.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stack&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
using namespace std;
int main ()
{
    cout&lt;&lt;"please enter a series of words with parenthes"&lt;&lt;endl;
    vector&lt;string&gt; svec;
    string word;
    while (cin&gt;&gt;word)
        svec.push_back(word);
    stack&lt;string, vector&lt;string&gt; &gt; strStack(svec);
    vector&lt;string&gt;::iterator pos1 ,pos2;
    for (vector&lt;string&gt;::iterator counter=svec.end(); strStack.empty()==false; --counter)
    {
        if(strStack.top()==")") pos1=counter-1;
        if(strStack.top()=="(") { pos2=counter-1; break; }
        strStack.pop();     
    }
    svec.insert(svec.erase(pos2,pos1),"(deleted)");
    for(vector&lt;string&gt;::iterator iter=svec.begin(); iter!=svec.end(); )
        cout&lt;&lt;*iter++&lt;&lt;" "&lt;&lt;flush;
return 0;
}
</code></pre>

<p>sorry. output is: I think the problem is  stack > strStack(svec);
cause I couldn't cout stack; the codes above this should be fine (i cout'ed them);</p>

<pre><code>please enter a series of words with parenthes
this is (a) duck
Segmentation fault
</code></pre>
