- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我这辈子都弄不明白为什么会出现这个调试错误:
检测到堆损坏:在正常 block (#126)之后0x004cF6c0CRT 检测到应用程序在堆错误结束后写入内存。
据我了解,无论何时使用 new 运算符都需要释放内存,我做了,但我仍然遇到问题。
由于某种原因,程序在递归函数中没有正确结束。我对其进行了调试,并通过断点遍历了每一行代码。
在 countSum 中的 if 语句的末尾,它以某种方式从 i 中减去 1然后重新进入 if block ......这是不应该做的。
为什么会这样?
/*this program calculates the sum of all the numbers in the array*/
#include <iostream>
#include <time.h>
using namespace std;
/*prototype*/
void countSum(int, int, int, int*);
int main(){
bool flag;
int num;
int sum = 0, j=0;
int *array = new int;
do{
system("cls");
cout<<"Enter a number into an array: ";
cin>>array[j];
cout<<"add another?(y/n):";
char choice;
cin>>choice;
choice == 'y' ? flag = true : flag = false;
j++;
}while(flag);
int size = j;
countSum(sum, 0, size, array);
//free memory
delete array;
array = 0;
return 0;
}
void countSum(int sum, int i, int size, int *array){
if (i < size){
system("cls");
cout<<"The sum is :"<<endl;
sum += array[i];
cout<<"...."<<sum;
time_t start_time, stop_time;
time(&start_time);
do
{
time(&stop_time); //pause for 5 seconds
}
while((stop_time - start_time) < 5);
countSum(sum, (i+1) , size, array); //call recursive function
}
}
最佳答案
array
为单个 int
保留足够的空间:
int *array = new int;
但可能会尝试插入多个 int
这将导致写入不可用的内存。要么使用 std::vector<int>
或者必须事先知道 int
的最大数量将在 array
之前输入的 s已分配。
如果这是一个学习练习并且您不想使用 std::vector<int>
您可以提示用户输入 int
的编号他们希望输入:
std::cout << "Enter number of integers to be entered: ";
int size = 0;
std::cin >> size;
if (size > 0)
{
array = new int[size];
}
然后接受size
数量int
秒。使用 delete[]
当你使用 new[]
.
关于c++ - 检测到堆损坏 : after Normal block (#126),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11569473/
这两种方法似乎都完成了从字符串中删除重音符号的相同工作,但我不确定是否存在一些内部差异,可以使一种方法优于另一种方法 最佳答案 分解处理的不仅仅是重音(在 Unicode 中称为标记),例如韩文音节
我在尝试绘制一些数据时收到此错误: findfont: Font family ['STIXGeneral'] not found. Falling back to DejaVu Sans. Trac
我理解规范化和规范化意味着删除数据表示中任何无意义或模棱两可的部分,将有效相同的数据转换为实际相同的数据。 例如,如果您想获取某些输入数据的哈希值,并且其他任何人对规范的相同数据进行哈希处理都获得相同
#!/usr/local/bin/perl use warnings; use 5.014; use Unicode::Normalize qw(NFD NFC compose); my $strin
我正在尝试将包含“áéíóú”等字符的字符串规范化为“aeiou”以简化搜索。 在对 this question 的回复之后我应该使用 Normalizer 类来完成它。 问题是 normalize
我正在尝试获取外语文本并输出人类可读、文件名安全的等效文本。环顾四周后,似乎最好的选择是 unicodedata.normalize(),但我无法让它工作。我试过将一些答案的确切代码放在这里和其他地方
我是 pymc 和贝叶斯统计的新手。在这里,我试图实现一个极其简单的 pymc 模型,以便与理论结果进行比较。在我的测试用例中,我假设正常先验为 mu~N(20,20) 并且可能性假设为 data~N
我正在编写一个 XPath 表达式,但我修复了一个奇怪的错误,但是以下两个 XPath 表达式之间有什么区别? "//td[starts-with(normalize-space()),'Posted
tf.random.normal 和 tf.distributions.Normal 有什么区别?或者 tf.distributions.Multinomial 和 tf.random.multino
第一步: xcodebuild -project Pods/Pods.xcodeproj build 第二个: xcodebuild archive -project 'test.xcodeproj'
我正在将 Adobe Xd 中的设计转换为 HTML 模板,其中一个元素建议使用以下 css 规则。 top: 149px; left: 54px; width: 463px; height: 2
我正在与另一位数据库设计人员就规范化进行有趣的讨论。在这个例子中,我们有一个 GameTitles 表,每条记录都必须包含游戏发布的年份。他说 2NF 要求所有内容都必须规范化,因此,要符合要求,年份
我正在尝试在 python 中加载文件。如果您运行下面的代码并加载仅包含英文单词的文件,它将加载得很好。 Listado.txt 是一个西类牙语文件,包含以下单词:abacá、abadí、abadía
我一个月前完成了这个游戏,直到今天一切都很好。我在线收到错误: odgovorNormalized = Normalizer.normalize(konResenje, Normalizer.Form
我正在使用gnutls aes加密,这是我的代码 const gnutls_datum_t * key; *key = (const char*)"tZOVP7o/u2vQB+4B/0O0ZqLWvy
我正在尝试训练一个用于面部性别和年龄检测的 cnn 模型。我的训练集包含彩色和灰度的面部图像。我如何标准化这个数据集?或者如何处理混合了灰度和彩色图像的数据集? 最佳答案 请记住,网络只会尝试了解您的
这是 DB 规范化理论中的一个概念: Third normal form is violated when a non-key field is a fact about another non-ke
我正在存储有关棒球统计数据的数据,并希望使用三个表来存储:players、battingStats 和 pitchingStats。就问题而言,每个球员都会有击球统计数据或投球统计数据,但不会两者都有
我现在正在学习推力。我有一个问题:如何用推力进行归一化? 我有一个有效的代码,但我想知道这是否是最佳方法。 struct square { __host__ __device__ float oper
所以我知道我自己可以如何解决这个问题,但是有人知道任何可以处理这个问题的现有库吗? (无论什么语言)? 最佳答案 此 API 仅支持英文,并具有职称规范化:http://api.dataatwork.
我是一名优秀的程序员,十分优秀!