Why is CString not preferred

Discussion in 'C++' started by Rajesh Garg, Jul 22, 2003.

  1. Rajesh Garg

    Rajesh Garg Guest

    Why and in what situations is CString not preferred?
    RVG
    Rajesh Garg, Jul 22, 2003
    #1
    1. Advertising

  2. Rajesh Garg

    Aggro Guest

    Rajesh Garg wrote:
    > Why and in what situations is CString not preferred?
    > RVG


    CString is not part of the standard C++. If you want to use the code you
    wrote for example in Linux or other non-windows system, you need to
    first code it. And when you do that, you won't propably get as good
    result as std::string is.

    And even if you are not currently thinking that your code, or part of
    its might be used on other system. That still might be the case in the
    future. That's why IMHO you should try to make your code standard, if
    there are not any good reason why not.
    Aggro, Jul 22, 2003
    #2
    1. Advertising

  3. Rajesh Garg

    MG Guest

    > Why and in what situations is CString not preferred?

    CString is not preffered as its pretty heavy in terms of string
    manipulation..
    e.g. it allows the "+" operation on strings...and ppl have tendency of using
    the + operation lousily...
    what they tend to forget is that this operation requires a memory
    alloc...copying the strings and freeing the memory earlier used...

    and its due to this reason...for good programming...CString should be
    avoided..
    MG
    MG, Jul 22, 2003
    #3
  4. MG wrote:
    >
    > > Why and in what situations is CString not preferred?

    >
    > CString is not preffered as its pretty heavy in terms of string
    > manipulation..
    > e.g. it allows the "+" operation on strings...and ppl have tendency of using
    > the + operation lousily...
    > what they tend to forget is that this operation requires a memory
    > alloc...copying the strings and freeing the memory earlier used...
    >
    > and its due to this reason...for good programming...CString should be
    > avoided..


    what are you talking about?
    CString is a string class like std::string or many other string classes
    out there. It does it's job. And if the job requires 2 strings to be
    catanated and the operator+ is the method to do it, well, then I guess
    this is what needs to be done. And guess what: every string class you can
    imagine will have to handle the case of allocating memory for the result,
    this is nothing specific to CString.

    The reason we don't talk about CString in this NG is that it is a
    proprietary string class like many others. There is exactly one string
    class which is standard and comes with every decent C++ compiler: std::string
    Thats the one we talk about in that NG.


    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jul 22, 2003
    #4
  5. Rajesh Garg

    MG Guest

    "Karl Heinz Buchegger" <> wrote in message
    news:...
    >
    >
    > MG wrote:
    > >
    > > > Why and in what situations is CString not preferred?

    > >
    > > CString is not preffered as its pretty heavy in terms of string
    > > manipulation..
    > > e.g. it allows the "+" operation on strings...and ppl have tendency of

    using
    > > the + operation lousily...
    > > what they tend to forget is that this operation requires a memory
    > > alloc...copying the strings and freeing the memory earlier used...
    > >
    > > and its due to this reason...for good programming...CString should be
    > > avoided..

    >
    > what are you talking about?
    > CString is a string class like std::string or many other string classes
    > out there. It does it's job. And if the job requires 2 strings to be
    > catanated and the operator+ is the method to do it, well, then I guess
    > this is what needs to be done. And guess what: every string class you can
    > imagine will have to handle the case of allocating memory for the result,
    > this is nothing specific to CString.

    right....
    but the ease with which these things are available in CString that i have
    seen people getting carried away and start using the heavy functions
    lavishly without realising the load it has...
    MG, Jul 22, 2003
    #5
  6. MG wrote:
    >
    > >
    > > what are you talking about?
    > > CString is a string class like std::string or many other string classes
    > > out there. It does it's job. And if the job requires 2 strings to be
    > > catanated and the operator+ is the method to do it, well, then I guess
    > > this is what needs to be done. And guess what: every string class you can
    > > imagine will have to handle the case of allocating memory for the result,
    > > this is nothing specific to CString.

    > right....
    > but the ease with which these things are available in CString


    Please enlighten me. In which way is it easier to catanate 2 strings
    with the help of CString then by using std::string?

    > that i have
    > seen people getting carried away and start using the heavy functions
    > lavishly without realising the load it has...


    .... and the very same holds true for every other string class.
    So there is only one conclusion from what you are telling us:
    don't use a string class at all.

    But that's definitly not what one wants to do.

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jul 22, 2003
    #6
  7. > > but the ease with which these things are available in CString
    >
    > Please enlighten me. In which way is it easier to catanate 2 strings
    > with the help of CString then by using std::string?
    >
    > > that i have
    > > seen people getting carried away and start using the heavy functions
    > > lavishly without realising the load it has...

    >
    > ... and the very same holds true for every other string class.
    > So there is only one conclusion from what you are telling us:
    > don't use a string class at all.


    Users of the std::string class can use the reserve() function to reduce
    the number of reallocations caused by for example concatenating strings.
    This function can be added very easilly once it has been proven that
    string concatenation is the performance bottleneck.

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
    Peter van Merkerk, Jul 22, 2003
    #7
  8. Rajesh Garg

    Tim Slattery Guest

    (Rajesh Garg) wrote:

    >Why and in what situations is CString not preferred?
    >RVG


    It's available only through Microsoft's MFC classes. That makes it
    proprietary and non-standard. If you're writing a program that will
    run somewhere other than windows, you're not going to have access to
    it. But you *always* have access to std::string, even if you're
    writing an MFC program for Windows.

    --
    Tim Slattery
    Tim Slattery, Jul 22, 2003
    #8
  9. Rajesh Garg

    Rajesh Garg Guest

    Thanks Everybody....actually i was looking for the same kinda
    discussion over the query. Its really helped.......though i am still
    not clear WHEE does CString stand


    "Peter van Merkerk" <> wrote in message news:<bfjapk$eveqc$-berlin.de>...
    > > > but the ease with which these things are available in CString

    > >
    > > Please enlighten me. In which way is it easier to catanate 2 strings
    > > with the help of CString then by using std::string?
    > >
    > > > that i have
    > > > seen people getting carried away and start using the heavy functions
    > > > lavishly without realising the load it has...

    > >
    > > ... and the very same holds true for every other string class.
    > > So there is only one conclusion from what you are telling us:
    > > don't use a string class at all.

    >
    > Users of the std::string class can use the reserve() function to reduce
    > the number of reallocations caused by for example concatenating strings.
    > This function can be added very easilly once it has been proven that
    > string concatenation is the performance bottleneck.
    Rajesh Garg, Jul 23, 2003
    #9
  10. Peter van Merkerk wrote:
    >
    > > > but the ease with which these things are available in CString

    > >
    > > Please enlighten me. In which way is it easier to catanate 2 strings
    > > with the help of CString then by using std::string?
    > >
    > > > that i have
    > > > seen people getting carried away and start using the heavy functions
    > > > lavishly without realising the load it has...

    > >
    > > ... and the very same holds true for every other string class.
    > > So there is only one conclusion from what you are telling us:
    > > don't use a string class at all.

    >
    > Users of the std::string class can use the reserve() function to reduce
    > the number of reallocations caused by for example concatenating strings.
    > This function can be added very easilly once it has been proven that
    > string concatenation is the performance bottleneck.


    This is an argumentation I can live with. But thats not what MG
    claimed in the first place :)

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jul 23, 2003
    #10
  11. Rajesh Garg

    Mike Wahler Guest

    Rajesh Garg <> wrote in message
    news:...
    > Why and in what situations is CString not preferred?


    For me, always. Why? I have no use for it, and the
    standard library provides a much better string type
    which is portable.

    In case you were unaware, 'CString' is not part of
    ISO standard C++, it's a Microsoft invention, specific
    to their 'MFC' library for Windows.

    -Mike
    Mike Wahler, Jul 24, 2003
    #11
  12. Rajesh Garg

    Mike Wahler Guest

    Rajesh Garg <> wrote in message
    news:...
    > Thanks Everybody....actually i was looking for the same kinda
    > discussion over the query. Its really helped.......though i am still
    > not clear WHEE does CString stand


    The 'CString' type 'stands' as a Microsoft Windows specific
    type. It's useless for any other platforms.

    Here, we discuss the ISO standard C++ langugae, which is
    portable to many platforms, and supplies a string type.


    BTW please don't top post. Thank you.

    -Mike
    Mike Wahler, Jul 24, 2003
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    4,497
  2. Quentin Crain
    Replies:
    8
    Views:
    458
    Terry Reedy
    Oct 11, 2003
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    838
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,661
    Smokey Grindel
    Dec 2, 2006
  5. Susan Rice
    Replies:
    4
    Views:
    3,050
    Gavin Deane
    Dec 1, 2006
Loading...

Share This Page