然后创建一个集合,然后用20000&#x2b之间的200个数字填充该集合; 1,然后继续打印出该集合内部的每个数字
#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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果运行编译器,它将向您显示几个错误:
所以,编译器告诉您问题和位置。
然后,在删除了问题问题并在for循环条件下纠正语义错误后,您将得到:
这将起作用。
If you run your compiler, it will show you several errors:
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:
This will work.