简体   繁体   English

'std::get_time' 尚未声明

[英]‘std::get_time’ has not been declared

I am using get_time() and mtkime() to convert the values of an object of my DateTime class to a unix timestamp so that I can easily compare two instances of my DateTime class.我正在使用 get_time() 和 mtkime() 将 DateTime 类的对象的值转换为 unix 时间戳,以便我可以轻松比较 DateTime 类的两个实例。 Here is my code for generating the time stamp这是我生成时间戳的代码

void DateTime::setTimeStamp() 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 );

This code compiles and works perfectly on my Mac.这段代码在我的 Mac 上编译并完美运行。 BUT it gives this as the only error when compiling it on a remote server.但是,在远程服务器上编译它时,这是唯一的错误。

DateTime.h:40:12: error: ‘std::get_time’ has not been declared
 using std::get_time;

The server's compiler has no problem finding mtkime in case that info is of help.如果信息有帮助,服务器的编译器可以毫无问题地找到 mtkime。

My Mac compiler version我的 Mac 编译器版本

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 9.0.0 (clang-900.0.37) Target: x86_64-apple-darwin16.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin配置:--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 9.0.0 (clang-900.0. 37) 目标:x86_64-apple-darwin16.7.0 线程模型:posix InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Server GNU compiler version服务器 GNU 编译器版本

gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) gcc (GCC) 5.3.1 20160406(红帽 5.3.1-6)

I got the version of the compilers on both my Mac and the remote server by running我通过运行获得了 Mac 和远程服务器上的编译器版本

gcc --version

DateTime.h日期时间.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*/

I was able to successfully compile my code on the server by adding "-std=c++11" to my compiling call.通过将“-std=c++11”添加到我的编译调用中,我能够在服务器上成功编译我的代码。 This works:这有效:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM