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++_Arrays_Corrupt - Fatal编程技术网

C++ 奇怪的临时数组损坏

C++ 奇怪的临时数组损坏,c++,arrays,corrupt,C++,Arrays,Corrupt,我试图创建一个排列,当我完成我的问题时,我收到这个奇怪的错误: Stack around the variable "temp" was corrupted 变量段位于嵌套的for循环中: for(int i = 0 ; i < str_length ; i++) { for(int j = 0 ; j < str_length ; j++) { char temp[1]; temp[1] = text[i]; te

我试图创建一个排列,当我完成我的问题时,我收到这个奇怪的错误:

Stack around the variable "temp" was corrupted
变量段位于嵌套的for循环中:

for(int i = 0 ; i < str_length ; i++)
{
    for(int j = 0 ; j < str_length ; j++)
    {
        char temp[1];

        temp[1] = text[i];
        text[i] = text[j];
        text[j] = temp[1];

        cout << text << endl;
    }
}
for(int i=0;i不能使用
temp[0]
访问第一个元素使用
temp[0]
访问第一个元素您只需要使用
char-temp;
并将其作为
temp=text[i];
等进行访问


您正在访问堆栈上超过temp一个字节的点,这是无效的。在这种情况下,因为您只需要一个字符,所以根本不需要数组。

您只需要使用
char-temp;
并将其作为
temp=text[i];
等进行访问


您正在访问堆栈上超过temp一个字节的点,这是无效的。在这种情况下,由于您只需要一个字符,因此根本不需要数组。

temp[1]不存在,您应该执行temp[0]。或者,类似这样:

char temp;
temp = text[i];
text[i] = text[j];
text[j] = temp;


temp[1]不存在,您应该执行temp[0]。或者,类似以下操作:

char temp;
temp = text[i];
text[i] = text[j];
text[j] = temp;


如果您想使用唯一的排列,则考虑使用<代码>(int j= i+1;< /代码>)如果您想使用唯一的排列,考虑使用<代码>(int j=i+1;< />代码>