gpt4 book ai didi

c++ - 使用ios_base::sync_with_stdio(false);编译错误

转载 作者:行者123 更新时间:2023-12-03 07:39:05 25 4
gpt4 key购买 nike

我为Eratosthenes筛子编写了此代码,但它在ios_base::sync_with_stdio(false);上给出了编译时错误。
当我删除该行时,代码正在执行。

#include<bits/stdc++.h>
using namespace std;

ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

void sieveOfEratosthenes(int n) {
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p=2; n>=p*p; p++) {
if (prime[p]) {
for (int i = p*p; i<=n; i+=p)
prime[i] = false;
}
}

for(int p=2; p<=n; p++)
cout <<p << " ";
}

int main() {
cout << "Hello World!\n";
int n;
cout << "Please enter an integer n\n";
cin >> n;
sieveOfEratosthenes(n);
}

最佳答案

移动

ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
进入主要功能工作:)

关于c++ - 使用ios_base::sync_with_stdio(false);编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65437430/

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