#include "stdafx.h"int main()
{
setlocale(LC_ALL,"chs"); CTime now = CTime::GetCurrentTime();
CString s = now.Format("%Y 年%m 月%d 日 %H 时%M 分%S 秒\r\n 本地表示:%c\r\n");
_tprintf(_T("%s"),s); return 0;
}
我看的一本书的原内容。//好多错
#include "stdafx.h"
#include <locale.h>
#include <atltime.h>
#include <ctime>
int main()
{
setlocale(LC_ALL,"chs"); CTime now = CTime::GetCurrentTime();
CString s = now.Format("%Y 年%m 月%d 日 %H 时%M 分%S 秒\r\n 本地表示:%c\r\n");
_tprintf(_T("%s"),s); return 0;
}
自己加的。
结果出现了error C2664: “ATL::CString ATL::CTime::Format(LPCTSTR) const”: 不能将参数 1 从“const char [48]”转换为“LPCTSTR”
求解!谢谢!还有那个参数1是怎说的?

解决方案 »

  1.   

    用 _T()、 _TEXT() 或 TEXT() 宏,以兼容UNICODE和ANSI的编译环境CString s = now.Format(_T("%Y 年%m 月%d 日 %H 时%M 分%S 秒\r\n 本地表示:%c\r\n"));
      

  2.   

    _T("")    TEXT("")     自动匹配
    L""  宽字符
      

  3.   

    Working with Strings 
      

  4.   


    #include <afx.h>
    #include <afxwin.h>             // 在project->settings里开启MFC static library
    //#include <locale.h>           // c语言本地化函数头文件,支持本地货币等,这里用MFC
                                    // 技术不需要他,因为MFC在底层已经封装了类似功能
    void main(void)
    {
    //setlocale(LC_ALL,"chs");  //告诉编译器,对我而言,中国就是本地
    CTime now = CTime::GetCurrentTime();   //取得当前系统时间,包括年月日等
    CString s = now.Format("%Y 年%m 月%d 日 %H 时%M 分%S 秒\r\n 本地表示:%c\r\n");
                            // 设置输出格式
    _tprintf(_T("%s"),s);   // TCHAR.H中定义的函数,可以根据系统定义的字符环境如
                                         // _UNICODE 
                            // 或 _MBCS来判断是使用unicode或多字节字符集
    printf("%s",s);         // 其实这里你这么写也是没错的,这就是告诉系统我将我的CSting
                            // 对象按多字节字符集输出
    }
      

  5.   

    谢谢啦dcmilan一开始我还以为你头像是匹马呢!