This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
string comparison C++
- From: beezaur <beezaur at myhome dot net>
- To: gcc-help at gnu dot org
- Date: Sat, 23 Mar 2002 02:14:18 -0800
- Subject: string comparison C++
I'm a novice C++ programmer and perhaps I'm making a mistake, but I
can't seem to find it.
I am trying to compare STL type strings, say
string s1("hello")
string s2("goodbye")
with the compare function, ie
s1.compare(1,2,s2,1,2)
I am using code verbatim from both my text, Deitel & Deitel "How to
Program C++ 3rd ed", and Josuttis' "The C++ Standard Library", yet g++
refuses to compile, saying "no matching function for call to..."
Has the syntax changed since my books were printed? Should I install
gcc 3.04? Maybe I'm missing some obvious error?
I'm using Red Hat Linux 7.2 (an upgrade from 7.1) and gcc (g++) 2.96,
which was on the RH 7.2 CD.
A small example of this problem is below:
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
int main()
{
string s1("string1"), s2("string2");
cout << "s1.compare(s2): " << s1.compare(s2) << endl; // ok
cout << "s1.compare(1,3,s2,1,3): " << s1.compare(1,3,s2,1,3) <<
endl; // not ok
return 0;
}
Thank you for any help or direction you can offer.
Scott Pollock
--
A day without math is like a day without sunshine.