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 >>

>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);

Thanks, I am so stupid not seeing that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.