然后创建一个集合,然后用20000&#x2b之间的200个数字填充该集合; 1,然后继续打印出该集合内部的每个数字

发布于 2025-01-23 17:30:10 字数 1022 浏览 2 评论 0原文

#include <iostream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>

//Create a set object to store a set of 200 randomly generated numbers from 1 to 10000. Use the for_each function and an anonymous function to display all the even numbers in the set.

using namespace std;

template <typename t>
void prints(t even) {
    void prints(t even) {
        if (even % 2) == 0;
        cout << "All the even numbers in the set are: " << even;
    }
}

int main()
{
    srand(time(0));
    set<int> nums;
    for (int i = 0; i < 200; i++) {
        nums.insert(rand() % 10000 + 1);
    }
    int gt50 = count_if(nums.begin(), nums.end(), [](int n) {return (n % 2) == 0}); // this is the issue it says I need ;, but when I put it nothing works. 

    for_each(nums.begin(), nums.end(), prints<int>);
}

我不明白为什么在第32行的结尾,它要求我实施;当我这样做时,命令要结束一行,它仍然会给我同样的问题。无论我不明白为什么这是在做我使用的调试器,但找不到任何东西的事情。

#include <iostream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>

//Create a set object to store a set of 200 randomly generated numbers from 1 to 10000. Use the for_each function and an anonymous function to display all the even numbers in the set.

using namespace std;

template <typename t>
void prints(t even) {
    void prints(t even) {
        if (even % 2) == 0;
        cout << "All the even numbers in the set are: " << even;
    }
}

int main()
{
    srand(time(0));
    set<int> nums;
    for (int i = 0; i < 200; i++) {
        nums.insert(rand() % 10000 + 1);
    }
    int gt50 = count_if(nums.begin(), nums.end(), [](int n) {return (n % 2) == 0}); // this is the issue it says I need ;, but when I put it nothing works. 

    for_each(nums.begin(), nums.end(), prints<int>);
}

I do not understand why, at the end of line 32 it is asking me to Implement the ; command to end of a line when I do so it still proceeds to give me the same issue. Regardless I don't understand why thats doing what its doing as I've used my debugger but cannot find anything out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2025-01-30 17:30:10

如果运行编译器,它将向您显示几个错误:

”在此处输入图像描述”

所以,编译器告诉您问题和位置。

然后,在删除了问题问题并在for循环条件下纠正语义错误后,您将得到:

#include <iostream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>

//Create a set object to store a set of 200 randomly generated numbers from 1 to 10000. Use the for_each function and an anonymous function to display all the even numbers in the set.

using namespace std;

template <typename t>
void prints(t even) {
    if ((even % 2) == 0) 
        cout << even << '\n';
}

int main()
{
    srand((unsigned int)time(0));
    set<int> nums;
    for (int i = 0; nums.size() < 200; i++) {
        nums.insert(rand() % 10000 + 1);
    }
    int gt50 = count_if(nums.begin(), nums.end(), [](int n) {return (n % 2) == 0; }); // this is the issue it says I need ;, but when I put it nothing works. 

    for_each(nums.begin(), nums.end(), prints<int>);
}

这将起作用。

If you run your compiler, it will show you several errors:

enter image description here

So, the compiler tells you the problem and where it is.

Then, after removing they problematic issues and correcting semantic bug in the for loops condition, you will get:

#include <iostream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>

//Create a set object to store a set of 200 randomly generated numbers from 1 to 10000. Use the for_each function and an anonymous function to display all the even numbers in the set.

using namespace std;

template <typename t>
void prints(t even) {
    if ((even % 2) == 0) 
        cout << even << '\n';
}

int main()
{
    srand((unsigned int)time(0));
    set<int> nums;
    for (int i = 0; nums.size() < 200; i++) {
        nums.insert(rand() % 10000 + 1);
    }
    int gt50 = count_if(nums.begin(), nums.end(), [](int n) {return (n % 2) == 0; }); // this is the issue it says I need ;, but when I put it nothing works. 

    for_each(nums.begin(), nums.end(), prints<int>);
}

This will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文