简体   繁体   English

DEVC/DEVC++ IDE 不支持向量吗

[英]does DEVC/DEVC++ IDE not support vectors

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> vect1(10);
    int value = 5;
    fill(vect1.begin(), vect1.end(), value);
    for (int x : vect1)
        cout << x << " ";
}

this does not compile in dev c++ and shows error.. i directly copied this code from gfg--> link is https://www.geeksforgeeks.org/initialize-a-vector-in-cpp-different-ways/ .这不能在开发 c++ 中编译并显示错误.. 我直接从 gfg 复制了此代码-> 链接是https://www.geeksforgeeks.org/initialize-a-vector-in-cpp-different-ways/

EDIT: it says range based for loops are not allowed in cpp98 version编辑:它说在 cpp98 版本中不允许基于范围的循环

im new to cpp any help is appreciated!我是 cpp 的新手,感谢您的帮助!

This <bits.stc++.h> is not a standard header file of GNU C++ library.<bits.stc++.h>不是 GNU C++ 库的标准 header 文件。 So some compiler may fail to compiler source code with this header file.因此,某些编译器可能无法使用此 header 文件编译源代码。 Include the <vector> and <iostream> headers in the project:在项目中包含<vector><iostream>标头:

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> vect1(10);
    int value = 5;
    fill(vect1.begin(), vect1.end(), value);
    
    for (int x : vect1)
        cout << x << " ";
}

References参考

Probably, Dev C++ has C++98 as default, and range-based for loop is from C++11 and onwards.可能,Dev C++ 默认使用 C++98,基于范围的 for 循环从 C++11 开始。

You click on Tools:你点击工具: 在此处输入图像描述

Click on Compile Options:点击编译选项: 在此处输入图像描述

Click on Settings:点击设置: 在此处输入图像描述

Click on Code Generation:点击代码生成: 在此处输入图像描述 On language standards, choose "ISO C++11"在语言标准上,选择“ISO C++11” 在此处输入图像描述

But you shouldn't use Dev C++ anymore.但是你不应该再使用 Dev C++ 了。

The problem is not the compiler.问题不在于编译器。 The #include <bits/stdc++.h> is a standard header which most of the sites use in their example codes and it includes a lot of other c++ header files but this is not defined in any C++ standard and not recommended at all because all compilers doesn't support it and it effects the portability of the code. The #include <bits/stdc++.h> is a standard header which most of the sites use in their example codes and it includes a lot of other c++ header files but this is not defined in any C++ standard and not recommended at all because all编译器不支持它,它会影响代码的可移植性。

Here is the detailed explanation of this: Why should I not #include <bits/stdc++.h>?这是对此的详细解释: 为什么我不应该#include <bits/stdc++.h>?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM