关于编译
  • 板块灌水区
  • 楼主Firefly_qwq
  • 当前回复15
  • 已保存回复15
  • 发布时间2022/11/24 20:50
  • 上次更新2023/10/27 01:39:30
查看原帖
关于编译
845053
Firefly_qwq楼主2022/11/24 20:50

今天看了GCC常用编译选项后尝试了一下,代码如下

#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  scanf("%d",&t);
  return 0;
}

我的编译指令是:

g++ -o moon moon.cpp -std=c++14 -O2 -Wall -Wextra

然后收到了警告:

moon.cpp: In function ‘int main()’:

moon.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

自己没找到问题于是去baidu了一下,将代码修改为如下后

#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  (void)scanf("%d",&t);
  return 0;
}

还是收到了警告:

moon.cpp: In function ‘int main()’:

moon.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

请问一下各位有什么办法让她正常编译吗

2022/11/24 20:50
加载中...