我正在使用boost 1_53在VS 2010中进行编译.我也在使用boost的线程.
在编译过程中我遇到了一堆像这样的错误
c:\ program files(x86)\ microsoft visual studio 10.0\vc\include\ctime(18):错误C2039:'clock_t':不是'`global namespace''的成员
所有错误都是关于ctime和c_time.hpp.
我一直在寻找解决方案,但没有成功.
有人可以,请帮忙吗?
这里是代码的一部分.
#define BOOST_THREAD_USE_DLL
#include <boost/optional.hpp>
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
Run Code Online (Sandbox Code Playgroud) 如何从系统启动以来获得系统启动时间?我发现的只是时代以来的时间而已.
例如,像ctime库中的time(),但它只给我一个自纪元以来秒的值.我想要像time()这样的东西但是从系统的开始.
考虑以下C ++代码
#include <ctime>
#include <iostream>
int main()
{
std::time_t now = std::time(nullptr);
struct tm local = *std::localtime(&now);
struct tm gm = *std::gmtime(&now);
char str[20];
std::strftime(str, 20, "%Z", &local);
std::cout << str << std::endl; // HKT
std::strftime(str, 20, "%Z", &gm);
std::cout << str << std::endl; // UTC
return 0;
}
Run Code Online (Sandbox Code Playgroud)
因此,其中存储的now是一个明确的整数值,而local和gm则struct tm存储了人类可读的日期/时间信息。然后,仅基于struct tm对象打印出格式化的信息(时区)。
根据CPLUSPLUS 参考,的数据成员struct tm是
tm_sec
tm_min
tm_hour
tm_mday
tm_mon
tm_year
tm_wday
tm_yday
tm_isdst
Run Code Online (Sandbox Code Playgroud)
如果仅此struct …
我有一个关于静态源代码分析的大型项目,一切都成功编译,除了一件事.我在标题中提供了错误消息.令我困惑的一点是,它给出了一条错误信息,说不安全.我认为应该只是警告,而不是错误.顺便说一下,我正在使用Visual Studio 2012.这是我在ctime中得到错误的代码的一部分.如果有人能帮助我克服这个错误,我会很高兴.
void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const std::size_t value)
{
(void)filename;
if (!time1)
return;
// Report progress messages every 10 seconds
const std::time_t time2 = std::time(NULL);
if (time2 >= (time1 + 10)) {
time1 = time2;
// current time in the format "Www Mmm dd hh:mm:ss yyyy"
const std::string str(std::ctime(&time2));
// format a progress message
std::ostringstream ostr;
ostr << "progress: "
<< stage
<< ' ' << value << '%';
if (_settings->_verbose)
ostr << " time=" …Run Code Online (Sandbox Code Playgroud) 我正在尝试从像"01/01/01"这样的字符串打印一个日期,并得到类似"2001年1月1日星期一"的内容.
我发现了一些与ctime的人有关但实际上并不知道如何使用它.
有帮助吗?
谢谢,
如何设置Unix文件的ctime?
(我更喜欢Python的答案.如果没有办法用标准的Python做,那么我认为C也可以.)
(注意:我知道可以使用os.utime来设置文件的atime和mtime.我对设置ctime很感兴趣.)
(注2:我希望有一个适用于任何POSIXoid Unix的答案,但如果没有,我对Darwin和Ubuntu感兴趣.)
我正在尝试使用ctime格式化一个10位的Unix时间戳(当前是一个字符串).
但是,ctime()需要一个类型为time_t的参数,而不是一个字符串.
在使用ctime之前我该怎么办?换句话说,我可以轻松地将字符串转换为time_t吗?
我如何计算某个函数(重复调用)的毫秒数?
我想到:
CTime::GetCurrentTM()之前,
CTime::GetCurrentTM()之后,
然后将结果插入CTimeSpan diff = after - before.
最后将diff存储到全局成员中,该成员总结所有差异,因为我想知道此函数花费的总时间.
但它会在几秒钟而不是几毫秒内给出答案.
我期望下面的代码应该打印不同的时间戳t1和t2,但结果显示t1和t2是相同的.我在哪里弄错了?
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
time_t t1 = time(NULL);
cout << "time now " << ctime(&t1) << endl;
time_t t2 = t1 + 10000.0;
cout << "time now " << ctime(&t1) << endl << " time later " << ctime(&t2) <<endl;
}
Run Code Online (Sandbox Code Playgroud)
结果:
time now Thu Apr 28 20:37:03 2016
time now Thu Apr 28 20:37:03 2016
time later Thu Apr 28 20:37:03 2016
Run Code Online (Sandbox Code Playgroud) 我正在用C++编写一个简单的日志记录类用于学习目的.我的代码包含一个返回今天日期字符串的函数.但是,每当调用"localtime"时,我都会收到编译错误.
std::string get_date_string(time_t *time) {
struct tm *now = localtime(time);
std::string date = std::to_string(now->tm_mday) + std::to_string(now->tm_mon) + std::to_string(now->tm_year);
return date;
}
Run Code Online (Sandbox Code Playgroud)
我试过用#define _CRT_SECURE_NO_WARNINGS.它没有工作,出现了同样的错误.我还尝试_CRT_SECURE_NO_WARNINGS在项目属性中放入预处理器定义.这给出了一个未解决的外部错误.
有没有人对如何做有任何想法?