| | |
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:
Solved Threads: 0
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!
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!
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:
C++ Syntax (Toggle Plain Text)
x = strcmp(word1.c_str(), word2.c_str());
I'm here to prove you wrong.
•
•
Join Date: Apr 2006
Posts: 164
Reputation:
Solved Threads: 10
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: compares str1 and str2 if they have same character.
try function..... find both length seperately using this function, then compare.... good luck!
•
•
•
•
int strcmp (const char str1[], const char str2[]);
try
•
•
•
•
int strlen (const char str[]);
A Perfect World
![]() |
Similar Threads
- TCHAR to std::string (C)
- Read a string from a binary file into a C or C++ string (C++)
- No matching function (C++)
- C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays (C++)
- need info? can't use strcmp/string compare (C++)
Other Threads in the C++ Forum
- Previous Thread: Going Insane
- Next Thread: I have C++ course
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






