注册 登录
编程论坛 C++教室

前辈帮忙看下这个字符转化为双精度数哪里错了?有点急!

瑞锋online 发布于 2017-12-28 15:20, 1866 次点击
这是我摘录出来的VC6.0下
CString mstr;
mstr+='7';
double m_num1=wcstod(mstr,NULL);
错误为:cannot convert parameter 1 from 'class CString' to 'const unsigned short *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
2 回复
#2
ehszt2017-12-28 15:54
错了编辑掉。

[此贴子已经被作者于2017-12-28 16:05编辑过]

#3
rjsp2017-12-28 15:56
首先,不要用VC6这么远古的编译器,若你喜欢微软,那也应该用最新的VC2017

其次,牛头要对马嘴
即 CString 对应着 TCHAR,CStringA 对应着 char,CStringW 对应着 wchar_t

#include <cstdio>
#include <atlstr.h>

int main( void )
{
    CString a;
    a += TEXT('7');
    printf( "%f\n", _tcstod(a,NULL) );

    CStringA b;
    b += '7';
    printf( "%f\n", strtod(b,NULL) );

    CStringW c;
    c += L'7';
    printf( "%f\n", wcstod(c,NULL) );
}
1