为什么在 sync_with_stdio(false) 之前使用 cin 给下一个 i/p 变量随机值
Why using cin before sync_with_stdio(false) give random values to next i/p variable
这是一个简单的代码:
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t,n;cin>>t;
cin.tie(NULL);
while(t--){
cin>>n;
cout<<n<<endl;
}
}
如果我输入
2
1
2
我得到了预期的输出 1
2
(换行)。
现在,如果我在 ios::sync_with_stdio(false);
之前使用 cin>>t
。那么对于相同的 i/p,o/p 是 0
0
(换行)。
AFAIK:ios::sync_with_stdio(false);
停止与 c++
和 c
i/p
o/p
的同步,但我在两个案例,为什么它不起作用?
此行为是实现定义的。
If this function(Here it refers to sync_with_stdio) is called after I/O has occurred on the standard stream, the behavior is implementation-defined: implementations range from no effect to destroying the read buffer.
这是一个简单的代码:
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t,n;cin>>t;
cin.tie(NULL);
while(t--){
cin>>n;
cout<<n<<endl;
}
}
如果我输入
2
1
2
我得到了预期的输出 1
2
(换行)。
现在,如果我在 ios::sync_with_stdio(false);
之前使用 cin>>t
。那么对于相同的 i/p,o/p 是 0
0
(换行)。
AFAIK:ios::sync_with_stdio(false);
停止与 c++
和 c
i/p
o/p
的同步,但我在两个案例,为什么它不起作用?
此行为是实现定义的。
If this function(Here it refers to sync_with_stdio) is called after I/O has occurred on the standard stream, the behavior is implementation-defined: implementations range from no effect to destroying the read buffer.