摘要: 下面代码是一个使用format的例子 ```c++ #include #include #include int main() { double principal{ 1000 }; double rate{ 0.5 }; std::cout 7.2f}\n", principal); std::c 阅读全文
posted @ 2023-08-14 21:59 yuzuki_n 阅读(92) 评论(0) 推荐(0) 编辑
摘要: ```c #include #include #include // 等待x毫秒 int sleep(unsigned long x) { clock_t c1 = clock(), c2; do { if ((c2 = clock()) == (clock_t) -1) return 0; } w 阅读全文
posted @ 2023-08-07 22:24 yuzuki_n 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 标准库算法不会改变它所操作的容器的大小,为什么back_insert不会让这一断言失效? 严格来说,算法不知道有容器这个东西,他只接受迭代器参数,运行在迭代器之上,通过迭代器访问元素。 因此,算法只能通过普通迭代器读取,改变,移动元素,但无法添加或删除元素。 但是插入器,能够用下层容器的操作来向容器 阅读全文
posted @ 2023-07-26 22:43 yuzuki_n 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 下面代码是否有错,怎么改 # 1 ```c++ vector vec; list lst; int i; while (cin >> i) lst.push_back(i); copy(lst.cbegin(), lst.cend(), vec.begin()); ``` 算法总是通过迭代器操作容器 阅读全文
posted @ 2023-07-23 14:16 yuzuki_n 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 用std::fill_n把一个int序列填充为0 ```c++ #include #include #include #include using namespace std; int main(int argc, char* argv[]) { vector v {1, 2, 3, 4, 5}; 阅读全文
posted @ 2023-07-18 22:58 yuzuki_n 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 用accumulate 计算一组double的和 注意点:accumulate 在头文件 `numeric` 而不是 `algorithm` accumulate的第三个参数是初始值,如果求double类型的值也用初始值0,那么数组中的其他值会被认为是int型,所以算出的结果不对 ```c++ #i 阅读全文
posted @ 2023-07-18 07:43 yuzuki_n 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 头文件algorithm中电仪了名为count的函数,它类似find,接受一对迭代器和一个值作为参数,count返回给定值在序列中出现的次数。编写程序,读取int序列存入vector中,打印有多少元素等于给定值 我的做法 ```c++ #include #include #include using 阅读全文
posted @ 2023-07-17 22:45 yuzuki_n 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 编写函数,以读模式打开一个文件,将内容读到一个vector《string》里面,将每一行为一个元素存到vector里面 ```c++ #include #include #include #include int main() { std::vector content; std::ifstream 阅读全文
posted @ 2023-07-15 08:30 yuzuki_n 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 题目:写一个函数,接受一个`istream&`参数,返回值也是`istream&`。该函数必须从给定流中读取数据,直至遇到文件结束标识符时停止。将他读取的函数打印在标准输出上。完成这些操作后,在返回流之前,对流进行复位,使其处于有效状态。 ```c++ #include #include #incl 阅读全文
posted @ 2023-07-11 22:27 yuzuki_n 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 我想写点什么 但是我不知道写点什么 但是我必须写点什么 阅读全文
posted @ 2023-06-18 21:24 yuzuki_n 阅读(3) 评论(0) 推荐(0) 编辑