如何调试错误消息“abort()已被调用”?

问题描述 投票:-8回答:1

代码下没有红线。当我开始没有调试时,在我输入电子邮件后,弹出一个失败,“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;
        }
    }
}
c++
1个回答
0
投票

我在你的代码中发现了很多问题。首先检查我关于你的for循环的评论。

接下来,在你的for循环中,如果第一个字符确实是'@',那么while循环将是一个无限循环,因为你永远不会突破它。

        while (x == '@')
        {
            a = 1;
            count++;
        }
© www.soinside.com 2019 - 2024. All rights reserved.