今天看了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]
请问一下各位有什么办法让她正常编译吗