Mail Archives: djgpp/2000/11/02/09:01:39
Rodeo Red wrote:
> Now Ive got a similar problem with replace() and I don't know if this is
> the same situation. How do I tell if my function is not supported ?
I'm not sure if there's a better way than simply trying it, or looking in
the header files (c:\djgpp\lang\cxx).
> I'd like to be able to know, because if it is supported, the error is
> probably mine.
I've downloaded Borland C++ 5.5, so I can always get a second opinion on
the correctness of my code. DJGPP is very good for C, but C++ is another
matter - although things should change once GCC 3.0 appears and is ported
to DJGPP. (Borland's compiler is probably buggier than GCC, but its
C++ library is currently more complete.)
> This is based on the example on page 1173 pf c++ Primer by Lippman and
> Lajoie, a reliable text.
Not so reliable if this is a real example from the book...
> #include <string>
> #include <algorithm>
You should have here:
#include <iostream>
using namespace std;
> int main()
> {
> string str = "The rain in Spain falls mainly on the plain\n";
> cout << "string:"<< str;
> string oldval = "rain";
> string newval = "sleet";
> replace (str.begin(), str.end(), oldval, newval) ;
This is incorrect. The function std::replace() replaces elements,
not sequences of elements. For example:
replace(str.begin(), str.end(), 'i', 'j');
This would replace every i in str by a j.
> cout << "new str:"<< str;
> }
- Raw text -