C++ 如何调试错误消息;abort()已被调用";?
代码下没有红线。当我在没有调试的情况下启动时,在我输入电子邮件后,会弹出一个失败消息,“abort()已被调用”。我如何调试这个C++ 如何调试错误消息;abort()已被调用";?,c++,C++,代码下没有红线。当我在没有调试的情况下启动时,在我输入电子邮件后,会弹出一个失败消息,“abort()已被调用”。我如何调试这个 #include <iostream> #include <string> using namespace std; int main() { string email; bool good = false; while (good == false) { there: cout <
#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;
}
}
}
#包括
#包括
使用名称空间std;
int main(){
字符串电子邮件;
bool good=false;
while(good==false)
{
在那里:
我在你的代码中看到了很多问题。首先检查我对你的for循环的评论
接下来,在for循环中,如果第一个字符确实是“@”,则while循环将是一个无限循环,因为您永远不会跳出它
while (x == '@')
{
a = 1;
count++;
}
在调试时启动它,你应该看到你在哪里访问某物。C++中的数组类实体的索引是0的,即你有索引0,……,长度-1。为什么你需要Goto?很可能是因为他们不知道<代码>继续< /代码> ok,但是如果你不显示任何调试,读者会假设你没有。做任何事。总是表现出你的努力——这真的可以避免一个问题被否决/结束。