c++ - 由于某种原因“printf_s”产生错误:“未在此范围内声明”
问题描述
我下载了 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.h
和cstdio
缺少声明。然而,VS2019 具有提供这些_s
功能的 MSVC 编译器。
推荐阅读
- amazon-web-services - AWS Lambda $LATEST 版本的定义
- azure - 如何限制 Azure 中的活动目录权限?
- ios - 自定义信号处理程序不适用于 iOS 上的 Firebase Crashlytics
- javascript - Node.js fs.readFile 返回文件的先前版本
- python - 我试图让我的程序创建一个文件来保存输入,但我不希望它出现两次。(Python)
- html - 如何构建一个宽度为 50% 的梯形菜单背景
- batch-file - what does ":2" mean in set variable in batch file
- php - Jquery ajax 不会将 POST 变量发送到 php
- java - 使用排序规则进行休眠搜索排序
- sql-server - 由于 GOTO 语句导致的性能问题