如何调试错误消息"abort() has been called"?

How to debug the error message "abort() has been called"?

本文关键字:has abort called been 错误 何调试 调试 消息      更新时间:2023-10-16

代码下没有红线。当我开始不调试时,输入电子邮件后,弹出了故障," Abort()被称为"。我该如何调试?

#include <iostream>
#include <string>
using namespace std;
int main() {
    string email;
    bool good = false;
    while (good == false)
    {
    there:
        cout << "Email is ";
        cin.ignore();
        getline(cin, email);
        cout << email.length();
        int a;
        for (int q = 0; q <= email.length(); q++)
        {
            char x = email.at(q);
            int count = 0;
            while (x == '@')
            {
                a = 1;
                count++;
            }
            if (count > 1)
            {
                a = 0;
            }
        }
        if ((email.at(0) == '@') || (email.at(email.length()) == '@') || (a == 0))
        {
            cout << "Input is invalid. One character ‘@’ must be found. Moreover, there must be some characters before and after the character ‘@’." << endl;
            goto there;
        }
        else
        {
            good = true;
        }
    }
}

我在您的代码中看到了很多问题。首先检查我的评论,以了解您的循环。

接下来,在您的循环中,如果第一个字符确实是"@",则您将是无限的循环,因为您永远不会脱离它。

        while (x == '@')
        {
            a = 1;
            count++;
        }