分段断层(堆芯倾倒)-Xubuntu
Segmentation fault (core dumped) - Xubuntu
我知道这个问题被问了很多,但我找不到适合我情况的答案。我的代码中没有指针,但我遇到了这个问题。我的程序是要考虑一个数字,尽管我还没能测试运行这个程序。我使用的是带有xfce的Ubuntu 16.04,所以实际上是xubuntu。main.cpp
#include <iostream>
using namespace std;
int main(){
int wholeNum;
int newNum;
int divider = 2;
int b;
int holderNum;
int remainNum;
bool stopper[wholeNum];
cin >> wholeNum;
while (wholeNum != divider){
holderNum = wholeNum / divider;
remainNum = wholeNum % divider;
if (remainNum == 0){
if (stopper[divider] != true || stopper[holderNum] != true){
cout << divider << " * " << holderNum << endl;
}
stopper[divider] = true;
stopper[holderNum] = true;
}
divider ++;
}
return 0;
}
我不知道发生了什么,因为我没有使用指针,而且它编译得很完美。如有任何帮助,我们将不胜感激!
当您声明数组时:
bool stopper[wholeNum];
wholeNum
仍然未定义。因此,数组stopper[]
具有未定义的大小。您需要首先输入wholeNum
的值(使用cin
),然后声明stopper[]
数组。所以基本上,像这样的东西:
int wholeNum;
//Other lines of your code
cin>>wholeNum;
bool stopper[wholeNum]; //---> Here value of wholeNum is defined.
这是成功编写的程序。
希望这能有所帮助!
相关文章:
- 分段故障(堆芯转储)矢量
- 数组的指针从不分段故障
- 在某些循环内使用vector.push_back时出现分段错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 在线编译器中的分段C++没有打印消息
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 当我的阵列太大时出现分段错误
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 分段错误当我试图运行程序时出错
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 尝试使用集合函数时出现分段错误
- 我无法缩小此分段错误的原因
- g++的分段错误(在NaN上使用to_string两次时)
- 我是如何在这段代码中出现分段错误的
- 创建结构的数组时遇到分段错误
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 在 c++ 中实现 Trie 时出现分段错误
- 为什么 fstream 在打开带有格式的文件时会导致分段错误?
- 为什么我遇到分段错误?
- 分段断层(堆芯倾倒)-Xubuntu