Why is CString not preferred

A

Aggro

Rajesh said:
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.
 
M

MG

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
 
K

Karl Heinz Buchegger

MG said:
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.
 
M

MG

Karl Heinz Buchegger said:
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...
 
K

Karl Heinz Buchegger

MG said:
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.
 
P

Peter van Merkerk

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?


... 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.
 
T

Tim Slattery

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.
 
R

Rajesh Garg

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
 
K

Karl Heinz Buchegger

Peter said:
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 :)
 
M

Mike Wahler

Rajesh Garg said:
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
 
M

Mike Wahler

Rajesh Garg said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top