473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why is CString not preferred

Why and in what situations is CString not preferred?
RVG
Jul 19 '05 #1
11 5464
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.

Jul 19 '05 #2
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
Jul 19 '05 #3


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
kb******@gascad.at
Jul 19 '05 #4
MG

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...


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...
Jul 19 '05 #5


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
kb******@gascad.at
Jul 19 '05 #6
> > 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
Jul 19 '05 #7
ra*******@rediffmail.com (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
Sl********@bls.gov
Jul 19 '05 #8
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" <me*****@deadspam.com> wrote in message news:<bf************@ID-133164.news.uni-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.

Jul 19 '05 #9


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
kb******@gascad.at
Jul 19 '05 #10
Rajesh Garg <ra*******@rediffmail.com> wrote in message
news:14**************************@posting.google.c om...
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

Jul 19 '05 #11
Rajesh Garg <ra*******@rediffmail.com> wrote in message
news:14*************************@posting.google.co m...
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

Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
8
by: Oskar | last post by:
Hi. I`m new in cpp and i have a litlle problem. i have a CString from Edit Box (eg."aaa bbb ccc 7327373 d feaf 323 dvjiv 234") and i want to put the data (space separated) into an array.It shuld...
5
by: Tim Wong | last post by:
All: I am trying to convert a CString value to an unsigned char array. I found some code online that will allow me to compile, but when I try to print out...i get a whole mess. /*Begin Code*/...
3
by: nsyforce | last post by:
What is the correct way to convert a const char* to a CString? I'm somewhat of a newbie and have tried several ways. While they all convert ok, I'm using a profiler that shows a memory leak for...
25
by: Gareth | last post by:
I want to do the following to strings: 1) Check if first four characters are "DATA" 2) Get the middle 'word' from the following string "DATA 123 xyz" (the middle word is variable length) -...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
4
by: Susan Rice | last post by:
I'm new to using CString. Why won't the following compile? I'm using Microsoft Visual C++ 6.0 Line 37 which it complains about is the function: 37 CString ConvertFile(char *szFileName) I...
2
by: flyingxu | last post by:
Hi, I run into a cstring related link problem in VC7. My solution has 3 projects, one MFC exe, two MFC extersion DLL. the two MFC extersion DLL export functions which use CString as parameters....
9
by: Donos | last post by:
I have a CString with 100 characters. Now i want to make that to 2 lines. For example, CString str = "This is just a test to find out how to break a cstring"; I want this CString in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.