Mail Archives: djgpp/2001/08/26/06:03:23
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 -