title: C++ - string.replace not working
body: <p>I am looking through some examples and I cannot seems to see why the string replace function is not working.  I am using Visual C++ 2010</p>
  
  <p>the line of code I am trying to compile is:</p>
  
  <pre><code>string MyClass::replacestr (const string &amp;input){
  
      string subString = "str";
      string subString2 = "STR";
  
      for(int index = input.find(subString);    index != string::npos;  index = input.find(subString, index +subString.length()))
      {
          input.replace(index, 2, subString2);
      }   
  
  }
  </code></pre>
  
  <p>It gives me this error in visual studio:</p>
  
  <pre><code>3   IntelliSense: no instance of overloaded function "std::basic_string&lt;_Elem, _Traits, _Ax&gt;::replace [with _Elem=char, _Traits=std::char_traits&lt;char&gt;, _Ax=std::allocator&lt;char&gt;]" matches the argument list and object (the object has type qualifiers that prevent a match)   c:\..test.cpp   36  Test
  </code></pre>
  
  <p>I just don't understand why it wont work the way it si explained in the c++ refernce website.</p>