C++ 代码未到达特定行

C++ Code not reaching a particular line

本文关键字:代码 C++      更新时间:2023-10-16

我正在用 c++ 编写代码,它的编译完美,但由于某种原因它没有超出特定行。我已经检查并重新检查了所有括号。我无法弄清楚为什么会发生这种情况,因为编译器也没有给我任何错误或警告。我没有包含整个代码,如果需要更多代码,请告诉我。

int main()
{
    //declaration of all the required variable used below
for(int g=0;g<e;g++)
{
    //some code here
}
for(int i=0;i<e;i++)
{
       //some code here
}

for(int k=1;k<v;k++)
{
    //some code here
}

cout<<"n";
cout<<"reaching here
for(int k=0;k<v;k++)
{
         //some code here
}
cout<<"n";  //printing a next line 
     cout<<"not printing this line";
return 0;
 }

问题可能是您打印的行之后没有行尾。如果不是这种情况,您应该能够附加调试器(我可以解释如何回答您是否可以使用哪种环境响应此答案:Win,Lin,Mac)并确定它崩溃的位置和时间。

C++ iostreams 为可移植的下线提供"std::endl",最好不要将其与""混合使用。

使用 ideone.com 我清理了粘贴的代码来编译和清理cout语句,它似乎有效:

int main()
{
    int e = 10;
    int v = 12;
    //declaration of all the required variable used below
    for(int g=0;g<e;g++)
    {
        //some code here
    }
    for(int i=0;i<e;i++)
    {
        //some code here
    }
    for(int k=1;k<v;k++)
    {
        //some code here
    }

    cout << endl << "reaching here" << endl;
    for(int k=0;k<v;k++)
    {
         //some code here
    }
    cout << endl << "not printing this line" << endl;
    return 0;
}

IDE链接:http://ideone.com/e6VShc

我认为它正在打印它,但您没有看到它,因为它与您编写命令的同一行中。