在CodeBlocks的Windows 8上使用cygwin64下的strptime

时间:2014-09-02 20:41:38

标签: c++ c cygwin

我正在尝试在我的Windows机器上编译一些最初用linux编写的代码。我安装了Cygwin并设置在CodeBlocks中使用,它主要工作。所有除了调用strptime之外的所有内容都以“错误:'strptime'向我致意。”我一直在谷歌搜索一段时间无济于事,请有人解释可能有什么问题吗?我试过包括time.h但没有运气。

#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE
#endif

#include <ctime>
#include <cstring>

class Date {
private:
  struct tm _tm;
  string strform;

  static void set_zero(struct tm &_tm) {
    memset(&_tm, '\0', sizeof(struct tm));
    //    _tm.hour = 0;
  }

  time_t make_time() {
    return mktime(&_tm);
  }

public:
  Date() {
    time_t current = time(NULL);
    _tm = *gmtime(&current);
    char buffer[1024];
    strftime(buffer, 1024, "%b %e %Y", &_tm);
    strform = buffer;
  }

  Date(time_t current) {
    _tm = *gmtime(&current);
    char buffer[1024];
    strftime(buffer, 1024, "%b %e %Y", &_tm);
    strform = buffer;
  }

  Date(string _strform) {
    strform = _strform;
    set_zero(_tm);
    char *result = strptime(strform.c_str(), "%b %e %Y", &_tm);
    assert(result);
    char buffer[1024];
    strftime(buffer, 1024, "%b %e %Y", &_tm);
    strform = buffer;
    //cout << "strform = " << strform << endl;
    //    cout << "length = " << result - strform.c_str() << endl;
    //    cout << "day = " << _tm.tm_mday << endl;
    //    cout << "month = " << _tm.tm_mon << endl;
    //    cout << "year = " << _tm.tm_year << endl;
    //    char buffer[1024];
    //    strftime(buffer, 1024, "%b %e %Y   %H:%M:%S", &_tm);
    //    cout << "buffer = " << buffer << endl;
  }

  Date operator-(int days) {
    return Date(make_time() - days*86400 );
  }

  time_t operator-(Date &other) {
    return (make_time() - other.make_time())/86400.0;
  }

  bool operator<=(Date &other) {
    return make_time() <= other.make_time();
  }

  bool operator<(Date &other) {
    return make_time() < other.make_time();
  }

  bool operator>=(Date &other) {
    return make_time() >= other.make_time();
  }

  time_t to_seconds() {
    return make_time();
  }

  friend ostream &operator<< (ostream &out, const Date &d) {
    return out << d.strform;
  }

  static Date today() {
    return Date();
  }

  string to_string() const {
    return strform;
  }

  const char *to_cstring() const {
    return strform.c_str();
  }
};

3 个答案:

答案 0 :(得分:1)

See this answer on XOPEN_SOURCE。通过将def lst = g.V().hasLabel('Person').toList(); def result = ["count":0, "data":[] ]; result.count=lst.size();result.data=lst[2..3];result添加到我的CMakeLists.txt,我有一些运气可以获得编译。结束时,编辑器通过转动标题中的特征来找到strptime。

答案 1 :(得分:0)

此错误消息表示未在找到函数时声明该函数。看起来strptime()在Cygwin的time.h文件中声明(至少在v1.7.25中),所以只需添加:

 #include <time.h>

到你的源文件。请注意,strptime()不是标准C函数。

答案 2 :(得分:0)

这只发生在C ++ 11及更高版本中。看起来import UIKit class SecondViewController: CubeController, CubeControllerDataSource, CubeControllerDelegate { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func numberOfViewControllersInCubeController(cubeController: CubeController!) -> Int { return 3 } func cubeController(cubeController: CubeController!, viewControllerAtIndex index: Int) -> UIViewController! { switch(index % 3){ case 0: return AViewController(nibName: "MyViewController", bundle: nil) case 1: return BViewController() case 2: return CViewController() default: return nil } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ 正在设置中,并且strptime()没有在其下定义。解决方法是取消__STRICT_ANSI__,如下所示。

__STRICT_ANSI__