www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/26/06:03:23

X-WM-Posted-At: MailAndNews.com; Sat, 25 Aug 01 21:09:44 -0400
X-WebMail-UserID: Ramiman12
Date: Sat, 25 Aug 2001 21:09:44 -0400
Sender: Ramy Elmeligy <Ramiman12 AT MailAndNews DOT com>
From: Ramy Elmeligy <Ramiman12 AT MailAndNews DOT com>
To: djgpp AT delorie DOT com
X-EXP32-SerialNo: 50000000
Subject: Program, uses compare() to check characters, but doesnt work
Message-ID: <3B8998F7@MailAndNews.com>
Mime-Version: 1.0
X-Mailer: InterChange (Hydra) SMTP v3.61.08
Reply-To: djgpp AT delorie 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

its really long, so i dont want to write out the whole thing here, but if 
someone needs it to help me out, ill put it up. Any help is greatly 
appreciated, as always.


//Exercise - Anagram Checker
#include <iostream>
#include <string>
using namespace std;

int main()
{
 string input1;
 string input2;

 cout << "Enter a line of text: ";
 getline(cin, input1);
 cout << endl;

 cout << "Enter another line of text: ";
 getline(cin, input2);
 cout << endl;

 cout << "Let's see if your strings are anagrams of each other. "
      << endl;

 int greater = 0;
 if(input1.length() > input2.length())
   greater = input1.length();
 else
   greater = input2.length();

 int equal = 0;

 int a = 0;
 int b = 1;
 int c = 0;

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

 for( ; ; )
  {
   for( ; a < greater, equal == 0 ; a++)
      input1.compare(a, b, input2, c, b);
   if(a >= greater)
     {
      a = 0;
      c++;
     }

  }


 if(equal != 0)
  {
   cout << "The strings are not anagrams.";
   return 0;
  }
 else
  {
   cout << "The strings are anagrams! What luck!";
   return 0;
  }
}


------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------

- Raw text -


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