From mboxrd@z Thu Jan 1 00:00:00 1970 From: SoloCDM Subject: Syntax Code Compiled Incorrectly Date: Wed, 11 Sep 2002 13:39:47 -0600 Sender: linux-gcc-owner@vger.kernel.org Message-ID: <3D7F9C03.9E261B40@cdm01.deedsmiscentral.net> Reply-To: deedsmis@aculink.net, linux-gcc@vger.kernel.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------422736D6292C7257F55E5E7E" Return-path: List-Id: To: "Linux-GCC (Majordomo)" This is a multi-part message in MIME format. --------------422736D6292C7257F55E5E7E Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Recently I tried to compile sstrcom.cpp with Kernel 2.2.20 on Linux Mandrake 8.0. I used "g++ sstrcom.cpp" and received the following errors: sstrcom.cpp: In function `int main ()': sstrcom.cpp:24: no matching function for call to `basic_string, __default_alloc_template >::compare (int, int, string &, int, int)' /usr/include/g++-3/std/bastring.cc:398: candidates are: int basic_string::compare (const basic_string &, unsigned int = 0, unsigned int = basic_string::npos) const [with charT = char, traits = string_char_traits, Allocator = __default_alloc_template] /usr/include/g++-3/std/bastring.cc:417: int basic_string::compare (const charT *, unsigned int, unsigned int) const [with charT = char, traits = string_char_traits, Allocator = __default_alloc_template] /usr/include/g++-3/std/bastring.h:402: int basic_string::compare (const charT *, unsigned int = 0) const [with charT = char, traits = string_char_traits, Allocator = __default_alloc_template] Everything points to "n = susername.compare( 0, 2, saname, 0, 2 );", even though the immediate line preceding it doesn't have any errors. What is wrong with the attached file? The output indicates that a function doesn't exist in ; if so, what library needs to be included? -- Note: When you reply to this message, please include the mailing list and/or newsgroup address and my email address in To: ********************************************************************* Signed, SoloCDM --------------422736D6292C7257F55E5E7E Content-Type: text/plain; charset=us-ascii; name="sstrcom.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sstrcom.cpp" // sstrcom.cpp // Comparing string objects #include #include using namespace std; /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ int main() { string saname = "George", susername; std::cout << "Enter your first name: "; cin >> susername; if ( susername == saname ) std::cout << "Greetings, George\n"; else if ( susername < saname ) std::cout << "You come before George\n"; else std::cout << "You come after George\n"; int n = susername.compare( saname ); n = susername.compare( 0, 2, saname, 0, 2 ); std::cout << "The first two letters of your name "; if ( n == 0 ) std::cout << "match "; else if ( n < 0 ) std::cout << "come before "; else std::cout << "come after "; std::cout << saname.substr( 0, 2 ) << endl; return 0; } --------------422736D6292C7257F55E5E7E--