Gle*_*leb 2 c++ visual-studio-2019
它不会影响我的代码,但是直到更新Visual Studio之前,我从未见过此类问题。我不知道那是否连接,但是我很困惑为什么会有问题。
#include <iostream>
#include <string>
#include <array>
using namespace std;
int main() {
const int SIZE = 3;
array<string, SIZE> names = { "S","A","W" };
array<string, SIZE>::iterator it;
cout << "names: \n";
for (it = names.begin(); it != names.end(); it++)
cout << *it << endl;
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Visual Studio更新后,他们向添加了一个[[nodiscard]]属性getchar。这告诉编译器在忽略函数的返回值时警告用户。您可以在此处找到更多信息:https : //en.cppreference.com/w/cpp/language/attributes/nodiscard
在这种情况下,由于getchar仅用于防止窗口关闭,因此不需要返回值,因此可以忽略此警告。
我们可以通过显式忽略返回值来使警告消失:
(void)getchar(); //Explicitly ignore return value
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |