strings and borlandC++

This is a discussion on strings and borlandC++ within the C++ Programming forums, part of the General Programming Boards category; In borland do I need to use the command line? Or can I get an IDE? And with strings, is ...

  1. #1
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    Exclamation strings and borlandC++

    In borland do I need to use the command line? Or can I get an IDE? And with strings, is that the only way to compare chars? Thx?
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    How do you mean you need strings to compare chars?
    Thats bull

  3. #3
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    I know I can compare single chars but how do I compare an array of chars. Example:
    char a[50]="greenhouse";
    char b;
    cout << "Enter greenhouse \n";
    cin >> b;
    if (b==a)
    {
    cout << "very good \n";
    }
    else
    {
    cout << "wrong \n";
    }
    .... // other stuff
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  4. #4
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Try....

    Code:
    if(strcmp(compare this, and this))
    {
         //
    }
    In cstring
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You'll want to read up on the standard string functions. For example "strcmp" is used to compare (case sensitive) for exact string matches.

    strcmp( astring, bstring );

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    explain more...

    Explain more or give me a site I can go to. (though I still think strings are easier!)
    What would be the upside of using char over string?
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  7. #7
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369

    Re: explain more...

    Originally posted by Stan100

    What would be the upside of using char over string?
    You can manipulate strings more, and you can have whitespace in strings.

    Oh, and I think strcmp returns false if the strings match, so maybe you'd want to use the ! operator
    Last edited by abrege; 12-17-2002 at 04:10 PM.
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  8. #8
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Command line only!

    The free Borland compiler is command line only.

    [\EDIT]

    Of course, you can write a DOS batch file and click on it to compile. I've done that when writing long programs and I've gotten tired of typing the same command line over and over.

    Some editors can invoke compilers too, but I've never used that feature.

    [EDIT\]
    Last edited by DougDbug; 12-17-2002 at 04:32 PM.

  9. #9
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    I like strings, but why would I use chars instead?
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  10. #10
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    I read your question wrong You can output chars more easily, and in some situations it is just unnecessary to use strings.
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    By way of information, a 'string' is a char array. Specialized, meaning more functional, but it's still a char array.

    Research the member functions of the 'string' class (basic_string) to see what all is available to you. I'd venture to say that the majority of the members of this Board have never, nor will ever, make use of the full functionality that the 'string' class affords you.

    We're weaned on traditional char arrays and are led, erroneously, to feel that using strings is akin to "cheating".

    I can see this attitude in an academic setting where some value can be placed on learning the foundations of the language, but , beyond that..."Prefer string operations to C-style string functions." Bjarne Stroustrup

    Now, before I get jumped all over and beaten badly - which I would look upon with disdain - there may, certainly, be situations where using chars may be preferred over strings. Can't think of any, at this moment, but...

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

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