473,803 Members | 2,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is CString not preferred

Why and in what situations is CString not preferred?
RVG
Jul 19 '05 #1
11 5503
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...C String 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...C String 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******@gasca d.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...C String 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.merke rk(at)dse.nl
Jul 19 '05 #7
ra*******@redif fmail.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....ac tually i was looking for the same kinda
discussion over the query. Its really helped.......th ough i am still
not clear WHEE does CString stand
"Peter van Merkerk" <me*****@deadsp am.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

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

Similar topics

6
24543
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 = source.GetBuffer(0 ); but i need a char* and so this is not working CString source = _T("TestString");
8
2313
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 be somethign like this. array1="aaa"; array1="bbb"; .... array1="234";
5
14079
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*/ CString day("01"); unsigned char testDay;
3
9153
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 every option. Here's what I have tried: const char* test; test = getMyChar(); //CString myCString((LPCTSTR)test); //CString myCString(test); CString myCString = new CString(test);
25
9924
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) - extract the "123". 3) Get the last word/number from the following string "DATA SEND 1467436267" What functions should I use to achieve this? I'm new to C++ and finding
4
4759
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++, there is no complain about the defintion. But
4
10505
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 tried throwing in a bunch of #includes but didn't help. Here's the compiler errors: Compiling...
2
5469
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. Everything is fine in VC6. Now I want to upgrade the solution to VC7, but I got lots of link error like this, /* WinGPC5.obj : error LNK2019: unresolved external symbol "public: static
9
8086
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 following format,
0
10555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10300
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.