zoukankan      html  css  js  c++  java
  • CString转换为string的做法

    http://zhidao.baidu.com/question/108564496.html

    CString wo("xxxxcc");
    string s;
    s=wo.GetBuffer();
    //失败了!!!
    //错误信息
    1>f:\c++试验\count_machine\count_machine\count_machinedlg.cpp(185) : error C2679: 二进制“=”: 没有找到接受“wchar_t *”类型的右操作数的运算符(或没有可接受的转换)
    1>        f:\vs 2005 主程序目录\vc\include\xstring(875): 可能是“std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)”
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Ax=std::allocator<char>
    1>        ]
    1>        f:\vs 2005 主程序目录\vc\include\xstring(880): 或“std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)”
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Ax=std::allocator<char>
    1>        ]
    1>        f:\vs 2005 主程序目录\vc\include\xstring(885): 或“std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)”
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Ax=std::allocator<char>
    1>        ]
    1>        试图匹配参数列表“(std::string, wchar_t *)”时
    --------------------------------------------------------------------

    CString wo("xxxxcc");
    string s(wo.GetBuffer());
    //失败了
    //错误信息
    1>f:\c++试验\count_machine\count_machine\count_machinedlg.cpp(184) : error C2664: “std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::allocator<_Ty> &)”: 不能将参数 1 从“wchar_t *”转换为“const std::allocator<_Ty> &”
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Ax=std::allocator<char>,
    1>            _Ty=char
    1>        ]
    1>        and
    1>        [
    1>            _Ty=char
    1>        ]
    1>        原因如下: 无法从“wchar_t *”转换为“const std::allocator<_Ty>”
    1>        with
    1>        [
    1>            _Ty=char
    1>        ]
    1>        无构造函数可以接受源类型,或构造函数重载决策不明确
    -------------------------------------------------------------------

    //还有 我把CString所有的成员函数都看了一遍,没有一个的返回值是string的
    //那如何才能实现CString到 string的转换啊?
    //如果能把CString转成string的话 我就可以有很多处理可以做,
    //因为学C++的时候都是用string的

    问题补充:
    回 vssvss:Format()用这个函数要包含什么头文件吧?报错:error C3861: “Format”: 找不到标识符---回aaa833:  CString wo("xxxxcc"); string s; s=(LPCTSTR)wo;//报错二进制“=”: 没有找到接受“LPCTSTR”类型的右操作数的运算符(或没有可接受的转换)operator =(const std::basic_string<_Elem,_Traits,_Ax> &)”//。。。。。。。。。1>        试图匹配参数列表“(std::string, LPCTSTR)”时回aaa833:  CString wo("xxxxcc"); string s; s=(LPCTSTR)wo;//报错1>f:\c++试验\count_machine\count_machine\count_machinedlg.cpp(185) : error C2679: 二进制“=”: 没有找到接受“LPCTSTR”类型的右操作数的运算符(或没有可接受的转换)可能是“std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)”//。。。。。。。。。1>        试图匹配参数列表“(std::string, LPCTSTR)”时 不行啊~~~大家答的答案都报错了~!!!!!!!!
  • 相关阅读:
    如何用C#代码管理SharePoint解决方案
    8 Reasons why SharePoint is Bad for Your Business 8个理由告诉你,为什么SharePoint对你的业务有害
    漫画教你了解SharePoint
    如何增强你的SharePoint 团队网站首页
    4 Reasons why SharePoint is Dying 四个理由告诉你,为什么SharePoint即将死去
    SharePoint 创建站点地图树视图及格式枚举截图
    C++虚函数与多态
    [DirectX 9.0笔记]第二章 渲染管线
    VC6.0 和 VS2010 time_t的区别
    [DirectX 9.0笔记]第一章 初始化 Direct3D
  • 原文地址:https://www.cnblogs.com/carl2380/p/1924566.html
Copyright © 2011-2022 走看看