how do i compare strings

This is a discussion on how do i compare strings within the C++ Programming forums, part of the General Programming Boards category; Im i right to say that you need string.h to compare char objects? If it is, that solves it...

  1. #16
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87

    what?!

    Im i right to say that you need string.h to compare char objects? If it is, that solves it

  2. #17
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    It's a matter of symantics. Technically you don't need string.h (or cstring depending on your compiler) to compare single chars. You do need string.h (or cstring) to compare null terminated char arrays (aka, c_style strings). If you consider a single char to be a char object then you don't need string.h. If you consider c_style string to be char objects you do. I know it's picky, but that's a large part of learning the language. Better to think of single char vs c_style string as opposed to char object. The latter is too vague, string is vague enough!!!!!

  3. #18
    Unregistered
    Guest

    Here's a little help

    Instead of using an else statement to check for illegal statements try this. By the way, this is only a piece of code.


    int checker=0;
    char yorn;

    while(checker=0)
    {
    cout<<"Choose y or n and input in lowercase";
    cin>>yorn;
    if(yorn="y")
    {
    checker=1;
    //do some other stuff
    }
    if (yorn="n")
    {
    checker=1;
    //do some other stuff
    }
    }

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compare strings problem
    By chelito19 in forum C Programming
    Replies: 2
    Last Post: 04-16-2009, 09:01 PM
  2. how do i compare first letters in two strings?
    By MalickT in forum C Programming
    Replies: 8
    Last Post: 04-20-2008, 06:47 PM
  3. compare strings not working
    By gtriarhos in forum C Programming
    Replies: 7
    Last Post: 09-29-2005, 01:51 PM
  4. Trying to compare to strings...
    By imortal in forum C++ Programming
    Replies: 9
    Last Post: 05-16-2003, 01:27 PM
  5. using Stacks & Queues to compare Strings
    By eskimo083 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2003, 05:03 PM

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