zoukankan      html  css  js  c++  java
  • cstring string 比较之二(学习笔记)

    cstring微软提供的,好象是ATL类库中提供的吧,只有vc带的库里面有。

    cstring耦合了根多的微软的东西,不能跨平台,只能在windows上使用。

    而string一般是指标准库中提供的std::string这个东西只要是标准的C++编译器里面就应该有这个东西的。

    string尽管各家编译器实现不一样,但是接口什么的东西是相同的,意味着可以跨平台。

    ==各种滋味,自己品味有使用 string的各种感受

    http://topic.csdn.net/u/20100309/10/6fb6a8d2-b4e2-42a9-a2c0-4914adac16cf.html

     

     

    如果使用WTL开发,那就肯定不会考虑跨平台(也跨不了,连编译器都跨不了)。

    所以,我认为CString是最好的选择。

     

    我现在使用wxWidgets,我就会用wxString。

    而当我用Qt开发时,我会用QString。

     

    已经尽量在避免使用std::string了,因为要跨编译器。

    GCC的std::string的引用计数,让我总提心吊胆。

    即使你使用std::string,在可移植性上也要小心。

     

    因为VC7以上的std::string不使用引用计数,而GCC的std::string是使用引用计数的。

     

    引用计数的实现有线程安全问题。

    ==

    ==============

    Reply 1 >> Re: Cstring Vs Std:String

     

     

    No.

    They are different...

    It's not only portability, it's the public interface, too.

    For example:

    1) CString plays well with Windows TCHAR model

    (instead you should overcome this with STL strings, using something like

    typedef std::basic_string< TCHAR > tstring; or something similar...).

    2) CString offers useful methods like Left, Right, etc. to extract subparts

    of the string.

    Moreover, it offers methods to trim trailing spaces, etc.

    3) CString is reference counted, instead I believe that std::string is not.

    //有对象概念

     

    4) CString has an implicit operator LPCTSTR such that you can use a Cstring

     

    whenever an API or something requires an LPCTSTR (const TCHAR *), instead

    you must call explicitly call .c_str() method from std::string.

    Probably there are other differences also...

    If you want to write Windows-only code, you may want to use CString, IMHO

    (but I believe that some valuable programmers here would suggest std::string

    instead...).

  • 相关阅读:
    SDN第二次上机作业
    SDN第二次作业
    SDN第一次上机作业
    个人作业-软件产品案例分析
    pandas之Series
    pandas简答介绍
    python爬取英文名
    python爬取动态网页
    python画树
    Python存储数据的方式
  • 原文地址:https://www.cnblogs.com/titer1/p/2308808.html
Copyright © 2011-2022 走看看