0

Anybody can help to explain why "m_line.replace(idx, m_search.size(), replace);" doesn't compile in cygwin and how to change it?
Thanks.

using namespace std;

int main(int argc, char *argv[])
{
  assert(argc==3 && 
    "Usage: <searchstring> replacestring> to process stdin");
  string m_line;
  string m_search(argv[1]);
  string m_replace(argv[2]);
  
  assert(m_search!=m_replace);
  
  while(getline(cin, m_line)) {
      while(true) {
          string::size_type idx = m_line.find(m_search);
          if(idx == string::npos) break;
          m_line.replace(idx, m_search.size(), replace);
      }
      cout << m_line << endl;
  }    
  
  system("PAUSE");	
  return 0;
}

<< moderator edit: fixed [code][/code] tags >>

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by banbangou
0

>Anybody can help to explain why "m_line.replace(idx, m_search.size(), replace);" doesn't compile in cygwin
Perhaps because replace isn't a valid third argument? How about:

m_line.replace(idx, m_search.size(), m_replace);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.