【发布时间】:2018-03-09 10:58:18
【问题描述】:
我正在使用 get_time() 和 mtkime() 将我的 DateTime 类的对象的值转换为 unix 时间戳,以便我可以轻松地比较我的 DateTime 类的两个实例。这是我生成时间戳的代码
void DateTime::setTimeStamp()
stringstream date_ss1;
date_ss1 << (*this);
istringstream date_iss(date_ss1.str());
struct tm date;
date_iss >> get_time( &date, "%Y/%m/%d-%H:%M" );
timestamp = mktime( &date );
此代码在我的 Mac 上编译并完美运行。 但是在远程服务器上编译时,这是唯一的错误。
DateTime.h:40:12: error: ‘std::get_time’ has not been declared
using std::get_time;
如果该信息有帮助,服务器的编译器可以毫无问题地找到 mtkime。
我的 Mac 编译器版本
配置: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM 版本 9.0.0 (clang-900.0.37) 目标:x86_64-apple-darwin16.7.0 线程模型:posix 安装目录: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
服务器 GNU 编译器版本
gcc (GCC) 5.3.1 20160406(红帽 5.3.1-6)
我通过运行获得了我的 Mac 和远程服务器上的编译器版本
gcc --version
日期时间.h
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <ctime>
#include <exception>
using std::ostream;
using std::istream;
using std::string;
using std::setfill;
using std::setw;
using std::endl;
using std::stringstream;
using std::istringstream;
using std::cout;
using std::invalid_argument;
using std::exit;
using std::get_time;
/*code*/
【问题讨论】:
-
在您的许多配置选项中是否有
-std=c++11? -
@StoryTeller 我该怎么做?我是个新手。
-
这是一个 GCC 编译器选项。您没有指定服务器如何调用它,但您应该确保它提供了该选项。
-
我使用了 g++ -std=c++11 my-file.cpp 并且它有效。谢谢!
标签: c++ c++11 datetime gcc time