no matching function for call to 'strcmp(std::string&, std::string&)'

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2006
Posts: 30
Reputation: newgurl is an unknown quantity at this point 
Solved Threads: 0
newgurl newgurl is offline Offline
Light Poster

no matching function for call to 'strcmp(std::string&, std::string&)'

 
0
  #1
Apr 8th, 2006
Hello,
I am one of those new assignment people, BUT I have tried to resolve this for a while now. Cant find much on google or other C++ sites.

I am trying to compare string lengths of 3 words and then display them in order of length.

My code is (I get stuck just before my first if statement):

#include <iostream>
#include <string.h>

using namespace std;

int main ()
{
int x,y,z;
string word1 = "word1 string";
string word2 = "word2 string";
string word3 = "word3 string";


cout<<"Please enter 3 words/n";
cin>>word1>>word2>>word3;

x = strcmp(word1, word2); ***THIS LINE IS THE PROBLEM***
{

if (strcmp (word1, word2)< 0)
wordA = word1
wordB = word2
}
if (strcmp (word1, word2) > 0)
{
wordA =word2
wordB =word1
}

y = strcmp (wordA, word3)
if (y < 0)
wordsml = wordA

z = strcmp (wordB, word3)
if (z < 0)
wordm = wordB

if (z > 0)
wordlge = word3

cout<<"The order of words from smallest to largest is "<<word sml<<" and "<<wordm<<" and "<<wordlge<,endl;

system("pause");
return 0

}

I know I have done something wrong in my setout, but the explanation given to me is not very clear to me and I dont know how to resolve : ******no matching function for call to 'strcmp(std::string&, std::string&)' ****** Can someone head me in the right direction?



Thanks!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,569
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 707
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: no matching function for call to 'strcmp(std::string&, std::string&)'

 
0
  #2
Apr 8th, 2006
strcmp takes C-style strings, not C++ string objects. The string class has overloaded the relational operators, so you can use < and > to compare them. But if you have your heart set on strcmp, you can do this:
  1. x = strcmp(word1.c_str(), word2.c_str());
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: no matching function for call to 'strcmp(std::string&, std::string&)'

 
0
  #3
Apr 9th, 2006
and u can use stricmp() instead of strcmp() to ignore upper case n lower case ..... actually this is not good way to compare string sizes....... bcoz:
int strcmp (const char str1[], const char str2[]);
compares str1 and str2 if they have same character.
try
int strlen (const char str[]);
function..... find both length seperately using this function, then compare.... good luck!
A Perfect World
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC