zoukankan      html  css  js  c++  java
  • C++中char cstring string互相转换

    1.CString字符串连接,避免用char* strcpy这样的方式好的多.

    CString World(“World”);

    CString HelloWorld = Hello + World;

    2.格式化字符串

    CString s;

    s.Format(_T(“%d”),IntVar);

    _T(x)代表让字符有unicode兼容性

    3:Cstring 到 char* 类型的相互转化.

    CString HelloWorld = CString(“Hello”) + CString(“World”);

    4:char* 转化为CString

    char * p = “This is a test”;

    TCHAR * p = _T(“This is a test”);

    CString Hello(“Hello”);

    5:CString转化char*

    CString对象包含三个值,一个指向缓冲区的指针,一个该缓冲中有效的字符计数以及一个缓冲区的长度.

    LPCTSTR操作符(或者更明确地说就是const TCHAR*操作符)在CString类中被重载了.

    CString s(“Hello World”);

    LPCTSTR p = s;

    可以转化:

    CString s(_T(“HelloWorld”));

    LPTSTR p = s.GetBuffer();

    if(p != NULL)

    *p = _T(\0);

    s.ReleaseBuffer();

    在GetBuffer和ReleaseBuffer方法之间,不能调用CString对象任何方法,因为这样对象将无法保证完整性.

  • 相关阅读:
    好用的辅助工具
    摆脱单体架构黑洞>>>>走向微服务的乐园
    什么是 jQuery 事件
    WebDriver一些常见问题的解决方法【转】
    IE浏览器相关的问题及解决方案[转]
    fix org.openqa.selenium.NoSuchWindowException when find element on ie11.
    BI案例:BI在连锁零售业应用(ZT)【转】
    SQL 基础语法(创建表空间、用户、并授予权限、数据的增删改查) --(学习笔记)[转]
    创建数据库和表的SQL语句【转】
    T-sql语句中GO的作用及语法【转】
  • 原文地址:https://www.cnblogs.com/sunliming/p/2068773.html
Copyright © 2011-2022 走看看