C++ 为什么我需要在main中编写std::ios::sync_和_stdio?
如果我写:C++ 为什么我需要在main中编写std::ios::sync_和_stdio?,c++,ios,gcc,C++,Ios,Gcc,如果我写: #include <iostream> using namespace std; main(){ ios::sync_with_stdio(false); cout << "hi"; } #包括 使用名称空间std; main(){ ios::与stdio同步(false); cout如果在main()之外编写带有stdio(false)的行ios::sync\u,编译器会将其解释为函数声明。然后,编译器会抱怨缺少模板 要调用函数,您需
#include <iostream>
using namespace std;
main(){
ios::sync_with_stdio(false);
cout << "hi";
}
#包括
使用名称空间std;
main(){
ios::与stdio同步(false);
cout如果在main()之外编写带有stdio(false)
的行ios::sync\u,编译器会将其解释为函数声明。然后,编译器会抱怨缺少模板
要调用函数,您需要编写如下内容:
bool std::ios_base::sync_with_stdio(bool sync)
{
//do something
return true;
}
bool result=std::ios::与stdio同步(true);
要重新定义静态函数,您需要编写如下内容:
bool std::ios_base::sync_with_stdio(bool sync)
{
//do something
return true;
}
更正为
std::ios_base::sync_with_stdio(false);
或者对于像cin
这样的特定流,您可以
cin.sync_with_stdio(false);
它应该在函数中,因为它是表达式而不是语句