Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未知错误,调试器只给我一个内存地址_C++_Debugging_Exception Handling - Fatal编程技术网

C++ 未知错误,调试器只给我一个内存地址

C++ 未知错误,调试器只给我一个内存地址,c++,debugging,exception-handling,C++,Debugging,Exception Handling,我正在尝试制作一个简单的快速排序算法,每当我运行它时,它都会抛出一个异常,我在调试时遇到了麻烦。错误为“Final.exe中0x00D01367处未处理的异常:0xC0000005:访问冲突写入位置0x00000000。”我是否无法使用s[I]=value并应使用s.push_back(值)而不是?我以前使用过前者,没有任何问题,所以我不明白为什么我现在会出错 #include <iostream> #include <vector> #include <list&

我正在尝试制作一个简单的快速排序算法,每当我运行它时,它都会抛出一个异常,我在调试时遇到了麻烦。错误为“Final.exe中0x00D01367处未处理的异常:0xC0000005:访问冲突写入位置0x00000000。”我是否无法使用
s[I]=value并应使用
s.push_back(值)而不是?我以前使用过前者,没有任何问题,所以我不明白为什么我现在会出错

#include <iostream>
#include <vector>
#include <list>
#include <cassert>
using namespace std;

typedef unsigned int uint;


uint partition(uint low, uint high, vector<double> & s)
{
uint i; //first index for partitioning
uint j; //second index for partitioning
uint pivotpoint; //index of the partition
double pivotvalue; //value at the pivot
double swapvalue; //placeholder variable for the swap

pivotvalue = s[low];
j = low;
for (i = (low+1); i<=high; i++)
{
    if (s[i] < pivotvalue)
    {
        j++;
        swapvalue = s[i];
        s[i] = s[j];
        s[j] = swapvalue;
    }
}
pivotpoint = j;
swapvalue = s[low];
s[low] = s[pivotpoint];
s[pivotpoint] = swapvalue;

return pivotpoint;
}

void quicksort(uint low, uint high, vector<double> & s)
{
uint pivotpoint;

if(high>low)
{
    pivotpoint = partition(low,high,s);

    if(pivotpoint != 0)
    {
        quicksort(low, pivotpoint-1, s);
    }
    if(pivotpoint != high)
    {
        quicksort(pivotpoint+1,high, s);
    }
}
}

int main( /*int argc, char* argv[] */)
{/*
  if( argc != 2 )
  {
cout << "Usage: ./filename.txt" << endl;
cout << "filename.txt should be a file with the items to be sorted" << endl;
exit( 2 );
  }
  assert(argc == 2)
  {
  }
  */
vector<double> s;
s[0] = 1.1;
s[1] = 2.4;
s[2] = 7.1;
s[3] = 5.4;
s[4] = 2.5;
s[5] = 1.2;
s[6] = 0.9;
quicksort(0,s.size(),s);
for(uint i = 0; i<s.size(); i++)
{cout << s[i] << endl;}
return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
typedef无符号整数单元;
uint分区(uint低、uint高、矢量和s)
{
uint i;//分区的第一个索引
uint j;//分区的第二个索引
uint pivotpoint;//分区的索引
double pivotvalue;//轴上的值
double swapvalue;//交换的占位符变量
数据透视值=s[低];
j=低;
对于(i=(低+1);i低)
{
枢轴点=分区(低、高、s);
如果(枢轴点!=0)
{
快速排序(低,支点-1,s);
}
如果(枢轴点!=高)
{
快速排序(枢轴点+1,高,s);
}
}
}
int main(/*int argc,char*argv[]*/)
{/*
如果(argc!=2)
{

cout一个直接的问题是向量初始化:

vector<double> s;
s[0] = 1.1;
s[1] = 2.4;
s[2] = 7.1;
s[3] = 5.4;
s[4] = 2.5;
s[5] = 1.2;
s[6] = 0.9;
在C++11中,您可以用以下内容替换整个内容:

vector<double> s{1.1, 2.4, 7.1, 5.4, 2.5, 1.2, 0.9};
向量s{1.1,2.4,7.1,5.4,2.5,1.2,0.9};

一个直接的问题是向量初始化:

vector<double> s;
s[0] = 1.1;
s[1] = 2.4;
s[2] = 7.1;
s[3] = 5.4;
s[4] = 2.5;
s[5] = 1.2;
s[6] = 0.9;
在C++11中,您可以用以下内容替换整个内容:

vector<double> s{1.1, 2.4, 7.1, 5.4, 2.5, 1.2, 0.9};
向量s{1.1,2.4,7.1,5.4,2.5,1.2,0.9};

您通常应该获得导致问题的代码的堆栈跟踪…堆栈跟踪显示的内容相同:
Final.exe中0x00D01367处未处理的异常:0xC0000005:访问冲突写入位置0x00000000。
多次。调用堆栈如下所示:>Final.exe!main()第71行C++ +MSVCR110!dll!第889行CYou通常应获得导致问题的代码的堆栈跟踪…堆栈跟踪显示的内容相同:
Final.exe中0x00D01367处未处理的异常:0xC0000005:访问冲突写入位置0x00000000。
多次。调用堆栈如下所示:>Final.exe!main()第71行C++ MMSCR110!DLL!