尚未声明“ std :: get_time”

‘std::get_time’ has not been declared

本文关键字:time get std 未声明      更新时间:2023-10-16

我正在使用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/cottents/developer/usr -with-gxx-include-dir =/usr/includs/cruppe/c /4.2.1 apple llvm版本9.0.0.0.0.0(clang-900.0.37)target:x86_64- apple-darwin16.7.0线程模型:posix 安装Dir: /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin

服务器GNU编译器版本

GCC(GCC)5.3.1 20160406(Red Hat 5.3.1-6)

我通过运行

在我的Mac和远程服务器上获得了编译器的版本
gcc --version

dateTime.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"添加到我的编译呼叫中,成功地在服务器上编译了我的代码。这有效:

g++ -std=c++11 DateTime.cpp