用时间类型的转换出错了

石灰石石英石 2011-10-08 09:01:46
警告:warning C4996:'swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter.To use traditional Microsoft swprintf,set_CRT__NON_CONFORMING_SWPRINTFS
错误:error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [26]”转换为“const wchar_t *” c:\users\administrator\desktop\2-3.cpp 121 1 os_test2_2-3

头文件:

//# include <windows.h>
# include <iostream>
# include <stdio.h>
# include <afx.h>
# include <cstring>
//#include <iostream.h> // b0:
static LPCTSTR g_szMutexName =(LPCTSTR) "w2kdg.ProcTerm.mutex.Suicide" ;

using namespace std;

main函数:
int main(int argc, char* argv[] )
{
// 决定其行为是父进程还是子进程

if (argc > 1 && strcmp(argv[1] , "child" )== 0)
{
Child() ;
}
else
{
Parent() ;
}
HANDLE hProcess;
FILETIME ftCreation, ftExit, ftKernel, ftUserStart, ftUserEnd;
LPSYSTEMTIME stCreation, stExit;
hProcess = GetCurrentProcess();
GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUserStart);
CTime cc(ftCreation);
CString str;
str.Format("Created at %02d:%02d:%02d", cc.GetHour(),
cc.GetMinute(), cc.GetSecond());

cout<<"调用GetProcessTimes函数: "<<str<<endl;
Sleep(5000);

return 0;
}
警告的地方: swprintf(szCmdLine, L"\"%s\" child" , szFilename) ;//命令行参数
出错的地方:str.Format("Created at %02d:%02d:%02d", cc.GetHour(), cc.GetMinute(), cc.GetSecond());
~~~~~~~~~~~~~~我是菜鸟,希望解释的清楚一点。thank you!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...全文
203 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-10-08
  • 打赏
  • 举报
回复
Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_stprintf sprintf sprintf swprintf

石灰石石英石 2011-10-08
  • 打赏
  • 举报
回复
第一次可以,但是现实的时间格式不对,不是00:00:00样子的
然后第二次执行就会报错

错误 1 error C2665: “swprintf”: 2 个重载中没有一个可以转换所有参数类型 c:\users\administrator\desktop\2-3.cpp 23 1 os_test2_2-3
疯魔症 2011-10-08
  • 打赏
  • 举报
回复
多字符集


//# include <windows.h>
# include <iostream>
# include <stdio.h>
# include <afx.h>
# include <cstring>
//#include <iostream.h> // b0:
static LPCTSTR g_szMutexName =(LPCTSTR) "w2kdg.ProcTerm.mutex.Suicide" ;

using namespace std;

main函数:
int main(int argc, char* argv[] )
{
// 决定其行为是父进程还是子进程

if (argc > 1 && strcmp(argv[1] , "child" )== 0)
{
Child() ;
}
else
{
Parent() ;
}
HANDLE hProcess;
FILETIME ftCreation, ftExit, ftKernel, ftUserStart, ftUserEnd;
LPSYSTEMTIME stCreation, stExit;
hProcess = GetCurrentProcess();
GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUserStart);
CTime cc(ftCreation);
CString str;
str.Format("Created at %02d:%02d:%02d", cc.GetHour(),
cc.GetMinute(), cc.GetSecond());

cout<<"调用GetProcessTimes函数: "<<str<<endl;
Sleep(5000);

return 0;
}
石灰石石英石 2011-10-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhao4zhong1 的回复:]

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_stprintf sprintf sprintf swprintf
[/Quote]
我是菜鸟,表示看不懂!

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧