From: Rodeo Red Newsgroups: comp.os.msdos.djgpp Subject: Re: compare() Date: Thu, 02 Nov 2000 11:52:29 -0500 Organization: Church of Evangelical Environmental Extremism Lines: 99 Message-ID: <7AB2F68195D27780.3FC067FFF65795BB.71FA8F3C8AC71107@lp.airnews.net> X-Orig-Message-ID: <3A019BCD DOT CCE80F6E AT netstep DOT 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> <3a017252 DOT 17107696 AT news DOT freeserve DOT net> Abuse-Reports-To: support at netstep.net to report improper postings NNTP-Proxy-Relay: library1-aux.airnews.net NNTP-Posting-Time: Thu Nov 2 10:42:24 2000 NNTP-Posting-Host: !\V&/-@[-pNcQKt (Encoded at Airnews!) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Steamer wrote: > > 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). Well I'll try, but since I easily get lost I'll describe the experience. I opened c:\djgpp\lang\cxx\string which did not have the prototypes for compare or replace but it did have #include So I opened c:\djgpp\lang\cxx\std\bastring.h and found this: int compare (const basic_string& str, size_type pos = 0, size_type n = npos) const; // There is no 'strncmp' equivalent for charT pointers. int compare (const charT* s, size_type pos, size_type n) const; int compare (const charT* s, size_type pos = 0) const { return compare (s, pos, traits::length (s)); } Only the last has an actual function. If these are the prototypes for compare(), where are the actual functions for the first two ? In another file I presume but I don't know where. Anyway, you posted 6 versions of compare, and there are three here, so does that mean these three area the ones supported by djgpp ? > > > 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. Good idea- I actually have it too but had trouble getting it to work. > 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 > > #include > > You should have here: > > #include > 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; > > } -- I'm not sure what you mean by "sequence". Do you mean you can't use a string class object ? According to Lippman and Lajoie, "replace() substitutes one or more characters within a string with one or more alternative characters ". Stroustrup says "Once a position is itentified, the value of individual character positions can be changed using subscripting or whole substrings can be replaced with new characters using replace(). basically I'd like to replace a character in a string with a second string. I guess I have to use substr(), but it seems like the long way. In looking at the prototypes for replace(), I'm wondering what const basic_string means. red