c++ - 整数或浮点变量的 C++ cin/coutSegmentation 错误,但对于 char 类型没问题
问题描述
cin >> num;
整数类型在线存在分段错误。
#include <iostream>
using namespace std;
int main(void)
{
int num;
printf("Hello World\n");
cin >> num; // seg fault line
system("pause");
return 0;
}
虽然 char 类型运行良好。
#include <iostream>
using namespace std;
int main(void)
{
char str;
printf("Hello World\n");
cin >> str;
system("pause");
return 0;
}
我正在使用 VSCode 和 MinGW,c_cpp_properties.json 如下:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x86"
}
],
"version": 4
}
解决方案
推荐阅读
- php - PHP - 获取在多个索引中具有值的键
- c# - 如何在WinForm中单击按钮的后台启动进程?
- javascript - 如何通过鼠标单击在法国 SVG 地图中显示部门名称?
- java - 最终用户使用 logcat 会看到什么日志?
- c# - 使用 .Net Core 2.1 创建 Azure Key Vault
- c++ - 带有翻译的 Qt Qml 树模型菜单
- python - Discord python将整个聊天导出到.txt文件
- reprojection-error - 使用 st_transform 重新投影 shapefile 的问题
- gulp-watch - GULP:仅重命名受影响的文件
- html - 如何为网络上的测验添加开始按钮和密码保护?