944,214 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2766
  • C++ RSS
Apr 26th, 2005
0

What's wrong with string.replace()?

Expand Post »
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.

C++ Syntax (Toggle Plain Text)
  1. using namespace std;
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5. assert(argc==3 &&
  6. "Usage: <searchstring> replacestring> to process stdin");
  7. string m_line;
  8. string m_search(argv[1]);
  9. string m_replace(argv[2]);
  10.  
  11. assert(m_search!=m_replace);
  12.  
  13. while(getline(cin, m_line)) {
  14. while(true) {
  15. string::size_type idx = m_line.find(m_search);
  16. if(idx == string::npos) break;
  17. m_line.replace(idx, m_search.size(), replace);
  18. }
  19. cout << m_line << endl;
  20. }
  21.  
  22. system("PAUSE");
  23. return 0;
  24. }
<< moderator edit: fixed [code][/code] tags >>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
banbangou is offline Offline
3 posts
since Mar 2005
Apr 26th, 2005
0

Re: What's wrong with string.replace()?

>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:
C++ Syntax (Toggle Plain Text)
  1. m_line.replace(idx, m_search.size(), m_replace);
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 27th, 2005
0

Re: What's wrong with string.replace()?

Thanks, I am so stupid not seeing that.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
banbangou is offline Offline
3 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: parking fee
Next Thread in C++ Forum Timeline: Need help with craps program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC