What's wrong with string.replace()?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 3
Reputation: banbangou is an unknown quantity at this point 
Solved Threads: 0
banbangou banbangou is offline Offline
Newbie Poster

What's wrong with string.replace()?

 
0
  #1
Apr 26th, 2005
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.

  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 >>
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,802
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #2
Apr 26th, 2005
>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:
  1. m_line.replace(idx, m_search.size(), m_replace);
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 3
Reputation: banbangou is an unknown quantity at this point 
Solved Threads: 0
banbangou banbangou is offline Offline
Newbie Poster

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

 
0
  #3
Apr 27th, 2005
Thanks, I am so stupid not seeing that.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC