delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/26/23:40:12

From: "Jesper Lund" <jl1204 AT worldonline DOT dk>
Newsgroups: comp.os.msdos.djgpp
References: <3B8998F7 AT MailAndNews DOT com>
Subject: Re: Program, uses compare() to check characters, but doesnt work
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Message-ID: <JH9i7.15426$3q.523303@news010.worldonline.dk>
Date: Sun, 26 Aug 2001 18:43:22 +0200
NNTP-Posting-Host: 212.54.71.88
X-Complaints-To: news-abuse AT wol DOT dk
X-Trace: news010.worldonline.dk 998844265 212.54.71.88 (Sun, 26 Aug 2001 18:44:25 MET DST)
NNTP-Posting-Date: Sun, 26 Aug 2001 18:44:25 MET DST
Organization: Customer of Tiscali A/S (World Online)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ramy Elmeligy <Ramiman12 AT MailAndNews DOT com> wrote in message
news:3B8998F7 AT MailAndNews DOT com...
> This program is supposed to check if two phrases entered are anagrams of
each
> other, by comparing every character in 'input1' to every character in
> 'input2'. It doesnt work, unfortunately; the compiler gives me a series of
> messages:
>
> anagram.cc(36) Error : no matching function for call to
'basic_string<char,
> string_char_traits<char>___default__alloc__template...etc
>

[snip]

>
>  input1.compare(a, b, input2, c, b) = equal;
>

Apparently, the std::basic_string class in gcc 2.95.3 does not include the
function

    int compare(size_type pos, size_type n, const basic_string& s,
                       size_type pos2, size_type n2) const;

as it should according to the C++ standard (well, I haven't checked the ANSI
C++ standard document, but Stroustrup 3e and Josuttis "The C++ Standard
Library" both mention the function). You see this by looking at the header
file \djgpp\lang\std\cxx\bastring.h (where the basis_string class is
defined; string is just a typedef for basic_string<char>).

Note: this behavior (bug, really) is _not_ specific to DJGPP (I got the same
error with Mingw). I don't know whether it has been corrected in gcc 3.0.

A quick workwound it to use input1.substr(a, b).compare(input2, c, b)
instead.



- Raw text -


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