摘要: #include <iostream> #include <random> namespace random { // 从系统获取随机数作为种子 std::random_device rd; // 创建种子序列 std::seed_seq rr{rd(), rd(), rd(), rd(), rd( 阅读全文
posted @ 2023-02-16 17:22 Leafmoes 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 在编写程序时,请考虑用户将如何滥用您的程序,尤其是在文本输入方面。对于每个文本输入点,请考虑: 会不会提取失败? 用户可以输入比预期更多的输入吗? 用户可以输入无意义的输入吗 用户可以溢出输入吗? 以下代码将清除任何无关的输入: std::cin.ignore(std::numeric_limits 阅读全文
posted @ 2023-02-16 14:26 Leafmoes 阅读(15) 评论(0) 推荐(0) 编辑
摘要: #include <algorithm> #include <cmath> #include <iostream> // 如果 a 和 b 之间的差异在 a 和 b 中较大者的 epsilon 百分比以内,则返回 true bool approximatelyEqualRel(double a, d 阅读全文
posted @ 2023-02-16 13:50 Leafmoes 阅读(38) 评论(0) 推荐(0) 编辑