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

时间:2017-12-17 20:46:50

标签: c++

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

1 个答案:

答案 0 :(得分:0)

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

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

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