【问题标题】:Why does the compiler not recognize some of the functions of a library?为什么编译器无法识别库的某些功能?
【发布时间】:2020-11-20 00:04:59
【问题描述】:

为什么编译器无法识别库的某些功能? 我在 Qt 中包含了 <ctime> 库,但无法识别它的功能。 为什么?我该如何解决我的问题?

【问题讨论】:

  • 发布代码和一些错误代码信息将帮助我们为您提供帮助!

标签: function qt time localtime ctime


【解决方案1】:

当然编译器会在正确包含库、正确使用函数(包含命名空间等)时识别它们

这个例子展示了如何使用 ctime 库来打印实际日期: 请注意,函数 time 包含在命名空间 std 中 因此std::time(...) 是一个有效的调用

#include "mainwindow.h"
#include <QApplication>
#include <ctime>
#include <iostream>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    std::time_t result = std::time(nullptr);
    std::cout << "x: "<< std::ctime(&result);
    return a.exec();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多