为什么CString不是首选 [英] Why is CString not preferred

查看:117
本文介绍了为什么CString不是首选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以及在什么情况下CString不是首选?

RVG

解决方案

Rajesh Garg写道:

为什么以及在什么情况下CString不是首选?
RVG




CString不是标准C ++的一部分。如果你想使用你在Linux或其他非windows系统中编写的代码,你需要首先对它进行编码。当你这样做时,你不会得到那么好的

结果为std :: string是。


即使你现在不是认为您的代码或其中一部分可能会在其他系统上使用。

的未来可能就是这种情况。这就是为什么恕我直言,你应该尝试使你的代码标准,如果

没有任何正当理由,为什么不。


< BLOCKQUOTE>>为什么以及在什么情况下CString不是首选?


CString没有优先考虑因为它在字符串

操作方面非常重要..

例如它允许+操作字符串...和ppl有倾向使用

+操作糟糕...

他们往往忘记的是这个操作需要一个内存

alloc ...复制字符串并释放先前使用的内存......


因为这个原因...为了良好的编程... CString应该是

避免..

MG





MG写道:

为什么以及在什么情况下CString不是首选?



CString没有优先考虑因为它很重要字符串
操作..
例如它允许+对字符串的操作...和ppl有倾向于使用+操作lousily ...
他们往往忘记的是这个操作需要一个内存分配...复制字符串并释放早先使用的内存...

由于这个原因......为了良好的编程... CString应该被避免..




你在说什么?

CString是一个字符串类,如std :: string或许多其他字符串类

。这是它的工作。如果这个工作要求2个字符串是

catanated并且操作符+是执行它的方法,那么我想

这是需要做的事情。并猜测:你可以使用每个字符串类
想象必须处理为结果分配内存的情况,

这对于CString来说并不是特定的。


我们在这个NG中没有谈到CString的原因是它和许多其他人一样是一个

专有的字符串类。只有一个字符串

类是标准的,并附带了每个不错的C ++编译器:std :: string

这就是我们在那个NG中谈论的那个。

-

Karl Heinz Buchegger
kb ****** @ gascad.at


Why and in what situations is CString not preferred?
RVG

解决方案

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.


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


这篇关于为什么CString不是首选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆