为什么我需要在main里面写std::ios::sync_with_stdio
Why do I need to write std::ios::sync_with_stdio inside main?
如果我写:
#include <iostream>
using namespace std;
main(){
ios::sync_with_stdio(false);
cout << "hi";
}
然后,程序编译正确,但是如果我写:
#include <iostream>
using namespace std;
ios::sync_with_stdio(false);
main(){
cout << "hi";
}
则GCC产生以下错误:
错误:特化成员'std::basic_ios::sync_with_stdio'需要'template<>'语法ios: sync_with_stdio(假);
这个错误意味着什么,以及如何纠正它(如果可能的话)?
如果在main()之外写ios::sync_with_stdio(false)
行,编译器会将其解释为函数声明。然后它抱怨缺少template<>
要调用这个函数,你需要这样写:
bool result = std::ios::sync_with_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);
它应该在函数内部,因为它是一个表达式而不是一个语句。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么 std::unique 不调用 std::sort?
- 为什么"std::printf"和"printf"在<cstdio>C++中使用而不是<stdio.h>时都会编译?
- #在stdio.h等C标准头文件中定义__CLIBNS::std::