声明向量会在NetBeans中引发运行时错误

时间:2022-05-13 15:28:33

I'm trying to learn about vectors in C++, but just trying to declare one throws a runtime error in NetBeans.

我正在尝试学习C ++中的向量,但只是尝试声明一个在NetBeans中引发运行时错误。

Error: Run failed (exit value -1, 073, 741, 511, total time 51 ms)

错误:运行失败(退出值-1,073,741,511,总时间51 ms)

PS: The code works perfectly in Eclipse.

PS:代码在Eclipse中完美运行。

#include <iostream>
#include <vector>

using namespace std;

int main() {
// create a vector to store int
vector<int> vec;
int i;

// display the original size of vec
cout << "vector size = " << vec.size() << endl;

// push 5 values into the vector
for (i = 0; i < 5; i++) {
    vec.push_back(i);
}

// display extended size of vec
cout << "extended vector size = " << vec.size() << endl;

// access 5 values from the vector
for (i = 0; i < 5; i++) {
    cout << "value of vec [" << i << "] = " << vec[i] << endl;
}

// use iterator to access the values
vector<int>::iterator v = vec.begin();
while (v != vec.end()) {
    cout << "value of v = " << *v << endl;
    v++;
}

return 0;
}

1 个解决方案

#1


0  

I have tested on my system (latest GCC and NB dev build) and it works without any problem. The desired output is shown. It also runs fine from command line.

我已经在我的系统上测试过(最新的GCC和NB dev版本),它没有任何问题。显示所需的输出。它也可以从命令行运行良好。

Therefore I assume it's more a configuration or system related problem. But without any further informations it's impossible to find the root cause.

因此,我认为这更多是配置或系统相关的问题。但是没有任何进一步的信息,找不到根本原因是不可能的。


More information please:

  1. What OS / Environment are you using?
  2. 您使用的操作系统/环境是什么?

  3. What Compiler (and versions) do you have?
  4. 你有什么编译器(和版本)?

  5. What version of Netbeans do you use?
  6. 您使用的是什么版本的Netbeans?

  7. Do other project's work?
  8. 做其他项目的工作吗?


Here's some first aid you can try:

  1. Create a new C++ Project (C++ Application). It already includes a blank main() function. Run this and check if there's still an error
  2. 创建一个新的C ++项目(C ++应用程序)。它已经包含一个空的main()函数。运行此命令并检查是否仍有错误

  3. Create a simple .cpp file and build it from command line (don't involve any IDE). Does it work this way?
  4. 创建一个简单的.cpp文件并从命令行构建它(不涉及任何IDE)。这样做有用吗?

  5. Build and your source file without IDE. From Commandline: g++ <your filename>.cpp
  6. 不使用IDE构建和您的源文件。从命令行:g ++ <您的文件名> .cpp

  7. Review your compiler settings (Tools -> Options -> C/C++ at Build Tools). Especially use the Version button and check if everything is right.
  8. 查看编译器设置(工具 - >选项 - >构建工具中的C / C ++)。特别是使用版本按钮并检查一切是否正确。

  9. Windows only: Make sure you have the correct make executable selected in the compiler settings
  10. 仅限Windows:确保在编译器设置中选择了正确的make可执行文件

  11. Have a look at the IDE's log (View -> IDE Log). Are there any problems mentioned?
  12. 查看IDE的日志(View - > IDE Log)。有没有提到的问题?

  13. Run in Debug without any breakpoint. This is going to stop the execution on any runtime error.
  14. 在Debug中运行,没有任何断点。这将停止执行任何运行时错误。

#1


0  

I have tested on my system (latest GCC and NB dev build) and it works without any problem. The desired output is shown. It also runs fine from command line.

我已经在我的系统上测试过(最新的GCC和NB dev版本),它没有任何问题。显示所需的输出。它也可以从命令行运行良好。

Therefore I assume it's more a configuration or system related problem. But without any further informations it's impossible to find the root cause.

因此,我认为这更多是配置或系统相关的问题。但是没有任何进一步的信息,找不到根本原因是不可能的。


More information please:

  1. What OS / Environment are you using?
  2. 您使用的操作系统/环境是什么?

  3. What Compiler (and versions) do you have?
  4. 你有什么编译器(和版本)?

  5. What version of Netbeans do you use?
  6. 您使用的是什么版本的Netbeans?

  7. Do other project's work?
  8. 做其他项目的工作吗?


Here's some first aid you can try:

  1. Create a new C++ Project (C++ Application). It already includes a blank main() function. Run this and check if there's still an error
  2. 创建一个新的C ++项目(C ++应用程序)。它已经包含一个空的main()函数。运行此命令并检查是否仍有错误

  3. Create a simple .cpp file and build it from command line (don't involve any IDE). Does it work this way?
  4. 创建一个简单的.cpp文件并从命令行构建它(不涉及任何IDE)。这样做有用吗?

  5. Build and your source file without IDE. From Commandline: g++ <your filename>.cpp
  6. 不使用IDE构建和您的源文件。从命令行:g ++ <您的文件名> .cpp

  7. Review your compiler settings (Tools -> Options -> C/C++ at Build Tools). Especially use the Version button and check if everything is right.
  8. 查看编译器设置(工具 - >选项 - >构建工具中的C / C ++)。特别是使用版本按钮并检查一切是否正确。

  9. Windows only: Make sure you have the correct make executable selected in the compiler settings
  10. 仅限Windows:确保在编译器设置中选择了正确的make可执行文件

  11. Have a look at the IDE's log (View -> IDE Log). Are there any problems mentioned?
  12. 查看IDE的日志(View - > IDE Log)。有没有提到的问题?

  13. Run in Debug without any breakpoint. This is going to stop the execution on any runtime error.
  14. 在Debug中运行,没有任何断点。这将停止执行任何运行时错误。