返回信息流我在VC6下试验stl里的random_shuffle算法,程序如下
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
int main()
{
int a[6] = {1, 2, 3, 4, 5, 6};
std::vector<int> v(a, a + 6);
srand(unsigned(time(NULL)));
std::random_shuffle(v.begin(), v.end());
std::ostream_iterator<int> output(std::cout, " ");
std::copy(v.begin(), v.end(), output);
std::cout << std::endl;
return 0;
}
但是查看了几十次输出结果之后发现输出序列竟然没有一次是以1作为开头的,感觉十分奇怪,不知道有没人有兴趣解答一下这个问题。
这是一条镜像帖。来源:北邮人论坛 / cpp / #45411同步于 2010/10/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
一个有趣的小问题
disk
2010/10/28镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
error C2039: “ostream_iterator”: 不是“std”的成员
error C2065: “ostream_iterator”: 未声明的标识符
vs2010下居然这样
【 在 disk 的大作中提到: 】
: 我在VC6下试验stl里的random_shuffle算法,程序如下
: #include <iostream>
: #include <vector>
: ...................
4 1 2 5 6 3
5 4 1 6 3 2
6 5 4 3 2 1
3 6 5 2 1 4
2 3 6 1 4 5
1 2 3 4 5 6
4 1 2 5 6 3
5 4 1 6 3 2
6 5 4 3 2 1
3 6 5 2 1 4
2 3 6 1 4 5
1 2 3 4 5 6
4 1 2 5 6 3
5 4 1 6 3 2
6 5 4 3 2 1
3 6 5 2 1 4
2 3 6 1 4 5
1 2 3 4 5 6
4 1 2 5 6 3
5 4 1 6 3 2
运行20次结果......