vs【visual studio】中显示stack around the variable “” was corrupted

作者在学习郝斌老师的课程中遇到栈溢出问题,源于VS对栈大小的限制。解决方案是在VS的配置属性中调整基本运行时检查。链接提供了进一步的帮助。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近,在学习郝斌老师的数据结构时,马上学完了,结果一个代码搞得我满脸懵。最后是怎么解决的呢?我第一次是在vs上写的,说栈溢出,然后到dev上,一点问题没有。

测试代码【放在vs和dev上很有意思,另外,今天是七夕节,祝大家早日脱单

 

#include <stdio.h>
void FastSort(int* p, int low, int high);
int FindPosition(int* p, int low, int high);
int main()
{
	int a[7] = { 5,2,0,1,3,1,4 };
	printf("该数组的长度为:%d\n", 7);
	
	FastSort(a, 0, 7);

	for (int i = 0; i < 7; i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}
void FastSort(int* p, int low, int high)
{	
	int pos = 0;
	if(low < high)
	{
		pos = FindPosition(p, low, high);
		FastSort(p, low, pos - 1);
		FastSort(p, pos+1, high);
	}
}
int FindPosition(int* p, int low, int high)
{
	//该函数包含了查找元素最终位置的过程  以及  具体的排序手法

	int val = p[low];
	while (low < high)
	{
		while (low < high && p[high] >= val)
			--high;
		p[low] = p[high];
		while (low < high && p[low] <= val)
			++low;
		p[high] = p[low];
	}
	p[low] = val;
	return high;
}

这段代码的问题出就出在了:在vs里,软件自己给你限制了栈的大小,而你的程序需要的栈超出了它的限制。

解决办法:vs主界面里 “project->配置属性->c/c++->代码生成->基本运行时检查 设置为默认值

参考链接:https://www.cnblogs.com/flysnail/archive/2011/09/21/2184114.html

好了,没有了

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值