c++ - 不能在 Xcode 中使用 _strdate (c++)

标签 c++ xcode

我想在我的 C++ 程序中显示当前日期和时间。我只是通过以下几行代码做到了这一点:

char date[9], time[9];

_strdate( date );
_strtime( time );

cout << "Current date and time: " << date << " " << time << endl;

这在 MS Visual C++ 2010 和 Dev C++ 4.9.9.2 中完美运行。但这在 Xcode 中不起作用!它说我正在使用未声明的标识符“strdate”和“strtime”。我已经包含了 iostreamctime 库,但这没有帮助。有什么问题?提前致谢。

最佳答案

std::string _strdate_alternative()
{
 char cptime[50];
 time_t now = time(NULL);
 strftime(cptime, 50, "%b. %d, %Y", localtime(&now)); //short month name
 return std::string(cptime);
}

如前所述,标准c/c++库中没有这样的函数。 您可以使用此替代方法。代码基于在 Internet 上找到的一些信息。我没有编译它。

关于c++ - 不能在 Xcode 中使用 _strdate (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11968403/

相关文章:

iOS/iPhone - Xcode 调试区域不显示对象属性

ios - 由于隐私敏感数据,应用程序在 iOS 11 上崩溃

iphone - 使用 SudzC 传递参数

iphone - 如何禁用 Xcode 中的按钮?

c++ - 填充与矩形相交的蒙版轮廓

C 从文件中读入方程

c++ - 用于简单数组创建和 i/o 的 C vs C++ 代码优化

c++ - 我应该有一个分配器作为我的类中的成员变量吗?

c++ - 如何编写会崩溃并生成转储文件的示例代码?

Linux 上的 C++ 动态共享库