title: Pick substrings from a input string
body: <p>I have a given requirement where valid input formats of a string are -:</p>
  
  <pre><code>- USD/AGR
  - USDAGR
  - +USD+AGR
  - -USD+AGR
  - -USD-AGR
  - +USD-AGR
  - +USD+AGR
  - +USD/AGR
  - -USDAGR
  - -USD/AGR 
  - USD-AGR
  
  and so on...
  </code></pre>
  
  <p>Inputs are in stringstream data type:
  Where '+' means to include this string for further calculation which is not the part of this program and '-' is not to include this string.</p>
  
  <p>I have to pick USD , AGR i.e. substring from the given string which is given as stream input. I have tried the below code, but it's failing in some cases. Please suggest a correction (note USD and AGR could be replaced with any 3 char like INR/JPY).</p>
  
  <p>// Example program</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;  
  #include &lt;stdio.h&gt; 
  #include &lt;algorithm&gt;
  
  using namespace std;
  #define CCY_LEN 3
  int main()
  {
      stringstream ss;
      string ss1 = "USD/SAR" , ss2;
  
      ss1.erase(std::remove(ss1.begin(), ss1.end(), '/'), ss1.end());
  
      cout&lt;&lt;ss1&lt;&lt;endl;
  
      ss.str(ss1);
  
      while(!ss.eof())
      {
          ss2.clear();
          ss.width(CCY_LEN+1);
          ss &gt;&gt; ss2;
  
          if(!ss2.size())
              break;
          if(ss2.at(0) == '-'){
              cout &lt;&lt;" 1 " &lt;&lt;ss2.substr(1, CCY_LEN)&lt;&lt;endl ;
          }
          if(ss2.at(0) == '+'){
              ss2.erase(std::remove(ss2.begin(), ss2.end(), '+'), ss1.end());
              cout &lt;&lt; " 2 " &lt;&lt; ss2.substr(0, CCY_LEN) &lt;&lt;endl;
          }
          else{
              cout &lt;&lt; " 3 " &lt;&lt;ss2.substr(0, CCY_LEN )&lt;&lt;endl ;
          }
      }
      return 0;
  }
  </code></pre>