is Dev C++ stupid? Or......

This is a discussion on is Dev C++ stupid? Or...... within the C++ Programming forums, part of the General Programming Boards category; I am trying to do string compares......I need to compare a user entry (stored in a string variable) against the ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    41

    is Dev C++ stupid? Or......

    I am trying to do string compares......I need to compare a user entry (stored in a string variable) against the elements of an array, until a match is found. Only trouble is, the compiler will not allow anything but a constant. That makes the function kind of useless, unless there is something specific I need to do.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You can't compare char* strings with ==. You need to use strcmp.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Disrupting the universe Mad_guy's Avatar
    Join Date
    Jun 2005
    Posts
    258
    If you're using C++ you might want to try the C++ STL String class instead, it overloads the == operator so I can do this:

    Code:
    string stuff = "ASDF";
    if("ASDF" == stuff) {
     //...
    }
    operating systems: mac os 10.6, debian 5.0, windows 7
    editor: back to emacs because it's more awesomer!!
    version control: git

    website: http://0xff.ath.cx/~as/

  4. #4
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Nope.

    In most cases, the general rule is:

    "THE COMPILER IS NEVER WRONG. YOU ARE."

    You don't think compilers are tested? They're beta tested out the ass....and in-house tested like mad before they even become beta versions...by many experts. Of course, this doesn't mean they're perfect.

  5. #5
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Krak
    Of course, this doesn't mean they're perfect.
    Krak had to add in that last part because of Micro$oft.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    41
    That's just it.
    Code:
    strnicmp(char* yourmom,YourMom[i]) //within an index loop
    I always get a 'cannot convert std::string to 'const' message.
    If I put in constants as the arguments, it works, but that obviously defeats the purpose of the function.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    strnicmp(char* yourmom,YourMom[i])
    No semicolon (although I assume you have one in).
    That char* shouldn't be there.
    strnicmp() is a non-standard function.

    I always get a 'cannot convert std::string to 'const' message.
    Try string_variable.c_str().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > I always get a 'cannot convert std::string to 'const' message.
    You're definitely taking a backward step if you're trying to use strcmp() and one of the strings in question is a std::string.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ( ) {
      string foo = "hello";
      if ( foo == "hello" ) {
        cout << "success" << endl;
      }
      return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 12:05 AM
  2. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 07:22 PM
  3. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 07:43 PM
  4. DEV C++ Limitations?
    By Kirdra in forum Game Programming
    Replies: 3
    Last Post: 09-09-2002, 09:40 PM
  5. Tutorial about Bloodshed Dev!
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-13-2001, 06:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21