为什么我的cpp程序在第一行之后挂断?

时间:2019-06-05 10:15:58

标签: c++

我在cpp中有此代码,是为了解决竞争性编码问题而编写的。 该代码似乎仅在第一行之后停止工作。即使删除第一行,代码也会在第二行挂断。我的CPU嗡嗡作响,好像遇到了无限循环。这两条线都不能启动无限循环。

参见此处:https://imgur.com/N4YZnCi

查看正在打印的行号。

然后我删除了我认为可能引起麻烦的行。但是随后代码似乎在后面挂了。

查看此内容:https://imgur.com/uZZeYFE

#include<bits/stdc++.h>

    #define line cout<<__LINE__<<"\n"; //this prints the line number in code

using namespace std;

int main() {
line  //This prints

ios_base::sync_with_stdio(false); cin.tie(NULL); 

line //This doesn't print at first

freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

line //This doesn't print in both attempts.
...
}

这从未发生过。我不明白的是,即使我可能在其他地方犯了一些错误,我也从未碰过这两行。这是我的竞争编码模板。这两行不应该独立于其余代码吗?

1 个答案:

答案 0 :(得分:0)

您正在将std::coutstdout_________________________________________________________________ Layer (type) Output Shape Param # ================================================================= input_1 (InputLayer) (None, 3937, 129) 0 _________________________________________________________________ conv1d_1 (Conv1D) (None, 981, 196) 379456 _________________________________________________________________ batch_normalization_1 (Batch (None, 981, 196) 784 _________________________________________________________________ activation_1 (Activation) (None, 981, 196) 0 _________________________________________________________________ dropout_1 (Dropout) (None, 981, 196) 0 _________________________________________________________________ gru_1 (GRU) (None, 981, 128) 124800 _________________________________________________________________ dropout_2 (Dropout) (None, 981, 128) 0 _________________________________________________________________ batch_normalization_2 (Batch (None, 981, 128) 512 _________________________________________________________________ gru_2 (GRU) (None, 981, 128) 98688 _________________________________________________________________ dropout_3 (Dropout) (None, 981, 128) 0 _________________________________________________________________ batch_normalization_3 (Batch (None, 981, 128) 512 _________________________________________________________________ dropout_4 (Dropout) (None, 981, 128) 0 _________________________________________________________________ time_distributed_1 (TimeDist (None, 981, 1) 129 ================================================================= Total params: 604,881 Trainable params: 603,977 Non-trainable params: 904 _________________________________________________________________ 断开连接。 cppreference has this to say:

  

如果在标准流上发生I / O之后调用此函数,则行为是实现定义的:实现范围从无效到破坏读取缓冲区。