Mail Archives: djgpp/2000/10/30/19:45:36
On Mon, 30 Oct 2000 01:02:05 -0500, Rodeo Red <rodeored AT netstep DOT net>
wrote:
>
>On my djgpp compiler I get the error messages below, and I thought it
>might be a compiler specific glitch. Does anyone know why this does not
>compile ? It compares the last three letters of the word with a string.
>
>
here is the original
>int main()
>{
> std::string word = "babies";
>
> std::string::size_type pos3 = word.size()-3;
> std::string ies("ies");
>
> std::cout << word << std::endl;
> std::cout << ies << std::endl;
>
> if (!word.compare(pos3, 3, ies))//line 16:no matching function
> {
> std::cout<< "yes the word ends in 'ies'";
> }
>
>
> std::cout << word << std::endl;
>
> return 0;
>}
here is the corrected copy
#include <iostream>
#include <string>
int main()
{
std::string word = "babies";
std::string ies("ies");
std::string::size_type pos3 = word.length() - ies.length() - 1;
std::cout << "the length of word is " << pos3 << std::endl;
std::cout << "word is " << word << std::endl;
std::cout << "string to test is " << ies << std::endl;
// this is my corrected attempt
if (( pos3 > 0 ) && (word.compare(ies, pos3)))
{
std::cout << "yes the word ends in 'ies'" << std::endl;
}else{
std::cout << "no the word doesn't end in 'ies'" << std::endl;
}
//this is the original code
//if (!word.compare(pos3, 3, ies))//line 16:no matching function
//{
// std::cout<< "yes the word ends in 'ies'";
//}
std::cout << word << std::endl;
return 0;
}
<error log snipped>
Your main problem was the incorrect call to compare. I did a quick
check of the info file and got the above version working. The other
changes I made like using length() were to ease the tests I ran.
Good luck! :)
Stan
- Raw text -