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



调试:运行时检查失败 #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:UsersMYNAMEsourcereposPythonVsCSVsC++DebugPythonVsCSVsC++.exe'. Symbols loaded.
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:WindowsSysWOW64ntdll.dll'. 
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:WindowsSysWOW64kernel32.dll'. 
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:WindowsSysWOW64KernelBase.dll'. 
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:WindowsSysWOW64msvcp140d.dll'. 
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:WindowsSysWOW64vcruntime140d.dll'. 
'PythonVsCSVsC++.exe' (Win32): Loaded 'C:WindowsSysWOW64ucrtbased.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 开始。

最新更新