C++ MFC 获取当前日期和时间
我的编程生涯的大部分时间都在使用 VB.NET 进行编程。我有一个 C++ 项目提供给我,我需要对其进行一些修改,我感到绝望和困惑。
它是一个 C++ 语言的 Visual Studio 2008 MFC 项目。
已定义输出变量:
char szout[900];
下面的这一行用于在输出之前将值附加到输出变量:
strcpy(szout, "TextHere")
因此,我尝试过的搜索的许多示例之一是包含在顶部:
#include <windows.h>
然后对于我的代码:
SYSTEMTIME st;
GetSystemTime(&st);
char myDate[20] = st;
CT2CA outputDate(myDate);
strcat(szout, outputDate);
由于某种原因,附加到 szout 的变量必须是 CT2CA 类型,我也不确定这是什么。
但后来我在第二行和第三行出现以下错误(char myDate...等...)和(CT2CA 输出...等...)
error C2440: 'initializing' : cannot convert from 'SYSTEMTIME' to 'char [20]'
error C2664: 'ATL::CW2AEX<>::CW2AEX(LPCWSTR) throw(...)' : cannot convert parameter 1 from 'char [20]' to 'LPCWSTR'
所以我要澄清一下,我是一个完全的新手对此,我们将不胜感激。
谢谢你,
I've been programming in VB.NET for most of my very programming career. I have a C++ project provided to me, which I need to make a few modifications, and I am feeling hopelessly lost and confused.
It is a Visual Studio 2008 MFC project in C++.
an output variable has been defined:
char szout[900];
This line below, is used to append values to the output variable before output:
strcpy(szout, "TextHere")
So one of the many examples from searching, that i have tried, was to include at the top:
#include <windows.h>
And then for my code:
SYSTEMTIME st;
GetSystemTime(&st);
char myDate[20] = st;
CT2CA outputDate(myDate);
strcat(szout, outputDate);
For some reason the variables appended on to szout must be of type CT2CA, which i'm not really sure what this is either.
But then I get the following errors on the second and third line (char myDate...etc...) and (CT2CA output....etc....)
error C2440: 'initializing' : cannot convert from 'SYSTEMTIME' to 'char [20]'
error C2664: 'ATL::CW2AEX<>::CW2AEX(LPCWSTR) throw(...)' : cannot convert parameter 1 from 'char [20]' to 'LPCWSTR'
So I'll clarify, I am a complete novice with this, and would appreciate any and all help.
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 MFC,为什么不:
If you are using MFC, why not:
在 MFC 中,以下代码用于获取 MMDDYYYY 格式的当前日期。
In MFC the following code is for current date in MMDDYYYY format.