由于某种原因"printf_s"产生错误:"not declared in this scope"



我下载了MinGW-64并运行了这段代码(由于它最初是一个堆栈、队列和其他DS实现,所以缩短了(:

#include <iostream>
#include <cstdio>
int main()
{
const int _sizeS = 20;
.
.
.
int _tmp;
printf_s("nEnter an alpha-numeric character to quit: ");

std::cin >> _tmp;
return 0;
}

这在VS2019中编译得很完美,并实现了我想要的功能。

然而,我在命令行中使用g++ pyrmd.cpp,并得到一个错误:

pyrmd.cpp: In function 'int main()':
pyrmd.cpp:6:2: error: 'printf_s' was not declared in this scope; did you mean 'printf'?
6 |  printf_s("n Enter a character: n");
|  ^~~~~~~~
|  printf

有人知道为什么会发生这种情况,以及如何解决吗?

我自己弄清楚了,并从评论中确认问题出在GCC本身。

GCC的包含库没有printf_s的声明。头文件stdio.hcstdio都缺少声明。然而,VS2019具有提供_s函数的MSVC编译器。

相关内容

最新更新