gpt4 book ai didi

c++ - 为什么我需要在 main 里面写 std::ios::sync_with_stdio?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:33 32 4
gpt4 key购买 nike

如果我写:

#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 产生以下错误:

error: specializing member 'std::basic_ios::sync_with_stdio' requires 'template<>' syntax ios::sync_with_stdio(false);

这个错误是什么意思,如何纠正(如果可能)?

最佳答案

如果你写这行 ios::sync_with_stdio(false)在 main() 之外,编译器将其解释为函数声明。然后它提示缺少 template<>

要调用该函数,您需要编写如下内容:

bool result = std::ios::sync_with_stdio(true);

要重新定义静态函数,您需要这样写:

bool std::ios_base::sync_with_stdio(bool sync)
{
//do something
return true;
}

关于c++ - 为什么我需要在 main 里面写 std::ios::sync_with_stdio?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31262546/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com