windows 如何在我的 vc++ 代码中包含 CTime
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5038150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include CTime in my vc++ code
提问by prabhakaran
I have a need to use CTime in my code. I tried to add the header file "atltime.h" to this code. But now, I am getting so many errors in compiling. Every error is coming from the header file "afxconv.h". I searched msdn for CTime, but they didn't describe about this( may be I yet to see the proper page). I am using VisualStudio-2008, 64 bit. Can anybody point me the correct direction?
我需要在我的代码中使用 CTime。我试图将头文件“atltime.h”添加到此代码中。但是现在,我在编译时遇到了很多错误。每个错误都来自头文件“afxconv.h”。我在 msdn 上搜索了 CTime,但他们没有对此进行描述(可能是我还没有看到正确的页面)。我使用的是 VisualStudio-2008,64 位。有人能指出我正确的方向吗?
采纳答案by prabhakaran
I included one file from code project, in that it uses some ASSERT,AfxisValidString. They included afx.h, for that. It is also the header for CTime. So, when I removed, and added atltime.h, then the ASSERT related things threw the errors. Sorry, I wated some of your precious time. I am going to vote to delete this question.
我包含了代码项目中的一个文件,因为它使用了一些 ASSERT、AfxisValidString。为此,他们包括了 afx.h。它也是 CTime 的标头。因此,当我删除并添加 atltime.h 时,与 ASSERT 相关的内容抛出了错误。抱歉,耽误了您宝贵的时间。我要投票删除这个问题。
回答by AndersK
Sounds like you are having a conflict with the MFC and ATL version of CTime. Since you specify MFC in your tag I suspect that you want the MFC verion. The atltime.h is for ATL projects. Afx.h has CTime for MFC which AFAIK is normally always included in the stdafx.h
听起来您与 CTime 的 MFC 和 ATL 版本有冲突。由于您在标签中指定了 MFC,我怀疑您想要 MFC 版本。atltime.h 用于 ATL 项目。Afx.h 有 MFC 的 CTime,AFAIK 通常总是包含在 stdafx.h 中
回答by madmik3
Can you show us your errors?
你能告诉我们你的错误吗?
this code works just fine on a 32 bit computer with a win32 project with atl.
这段代码在带有 atl 的 win32 项目的 32 位计算机上工作得很好。
#include "stdafx.h"
#include <atltime.h>
int _tmain(int argc, _TCHAR* argv[])
{
CTime ct;
printf("day of week %d\n",ct.GetDayOfWeek());
return 0;
}
回答by Mahesh
You need to have #include <time.h>
. Check the requirements part of the link. MSDN CTime
你需要有 #include <time.h>
. 检查链接的要求部分。MSDN CTime