| | |
What's wrong with string.replace()?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 3
Reputation:
Solved Threads: 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.
<< moderator edit: fixed [code][/code] tags >>
Thanks.
C++ Syntax (Toggle Plain Text)
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; }
>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:
Perhaps because replace isn't a valid third argument? How about:
C++ Syntax (Toggle Plain Text)
m_line.replace(idx, m_search.size(), m_replace);
I'm here to prove you wrong.
![]() |
Similar Threads
- String.replace() Method (Java)
- stupid string replace! (c++) (C++)
- Problem with String replaceAll method (Java)
- Using string variables in a label or text box? (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: parking fee
- Next Thread: Need help with craps program
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






