gpt4 book ai didi

c++ - 调试 : Run-Time Check Failure #2 - Stack around the variable 'LoggerThread' was corrupted

转载 作者:行者123 更新时间:2023-11-30 04:46:02 25 4
gpt4 key购买 nike

调试:运行时检查失败 #2 - 变量“LoggerThread”周围的堆栈已损坏。

我找不到解决方案 :( 无论如何都可以解决这个问题。

#include <iostream>

using namespace std;

int main()
{
string LoginMessage = "Please Login";
string loginsuccess = "Login Correctly";
float x = 0;
char afpl[6][7] = {

"A",
"B",
"C",
"@",
"*$",
"$"
};

cout << LoginMessage << endl;

float y = 10;
cin >> x;

int i = /* Would be random - */ 20;

int finalx = x + y * i;
int temp = finalx;
int last = temp / i;
if (last > 5) {
last = last / 3;
}

cout << afpl[last] << "|" << last << "|" << finalx << endl;
if (finalx == 210) {
if (last == 3) {
if (afpl[6][7] = '@') {
cout << loginsuccess << endl;
}
}
}

}

没有警告,只有错误,这是输出

'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Users\MYNAME\source\repos\PythonVsCSVsC++\Debug\PythonVsCSVsC++.exe'. Symbols loaded.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'.
The thread 0x188c has exited with code 0 (0x0).
Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted.

我该如何解决这个问题,我尝试到处寻找解决方法,但所有解决方案都没有解决我的问题。无论如何要解决这个问题:),顺便说一下,这是 c++。

最佳答案

if (afpl[6][7] = '@') 行正在分配给 afpl。我想你的意思是 if (afpl[6][7] == '@')。此外 afpl[6][7] 超出范围。这是未定义的行为,是导致堆栈损坏的原因(写入不正确的内存位置)。数组索引从 0 开始。

关于c++ - 调试 : Run-Time Check Failure #2 - Stack around the variable 'LoggerThread' was corrupted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56996541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com