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对象任何方法,因为这样对象将无法保证完整性.

  • 相关阅读:
    Repository中进行模糊查询
    Spring jpa添加查询条件
    java后端repository层中进行模糊查询
    MyBatis小白问题 1、Invalid bound statement (not found): com.itheima.dao.UserDao.findAll,2、Resources.getResourceAsStream()报错
    Date类型做加减运算
    时间格式转换
    mysql-支持的数据类型
    mysql—表的完整性约束
    数据库—表操作(第二章)
    mysql—使用python操作mysql数据库(第五章)
  • 原文地址:https://www.cnblogs.com/sunliming/p/2068773.html
Copyright © 2011-2022 走看看