delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/02/09:01:39

From: dontmailme AT iname DOT com (Steamer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: compare()
Date: Thu, 02 Nov 2000 13:56:29 GMT
Organization: always disorganized
Lines: 47
Message-ID: <3a017252.17107696@news.freeserve.net>
References: <1F7509A3BB20243A DOT 7FD3AC2DC483DD04 DOT 6BB6DE9721314E90 AT lp DOT airnews DOT net> <39fea8f5 DOT 9349153 AT news DOT freeserve DOT net> <2D3CEFEF9F5772C9 DOT 21D15067E7ACE130 DOT 3275BE6B77FD834E AT lp DOT airnews DOT net> <39fecce1 DOT 18547083 AT news DOT freeserve DOT net> <E80A6618268722F2 DOT 334C4577FE04F5AA DOT 3D933E68350DF73B AT lp DOT airnews DOT net>
NNTP-Posting-Host: modem-74.black-trigger.dialup.pol.co.uk
X-Trace: newsg2.svr.pol.co.uk 973173390 19281 62.136.233.74 (2 Nov 2000 13:56:30 GMT)
NNTP-Posting-Date: 2 Nov 2000 13:56:30 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019