C++面向对象程序设计 028:简单的foreach ---- (北大Mooc)
发布日期:2021-06-30 22:27:46 浏览次数:2 分类:技术文章

本文共 660 字,大约阅读时间需要 2 分钟。

文章目录


专题博客链接


原题题目

在这里插入图片描述

#include 
#include
using namespace std;// 在此处补充你的代码void Print(string s){
cout << s;}void Inc(int & n){
++ n;}string array[100];int a[100];int main() {
int m,n; while(cin >> m >> n) {
for(int i = 0;i < m; ++i) cin >> array[i]; for(int j = 0; j < n; ++j) cin >> a[j]; MyForeach(array,array+m,Print); cout << endl; MyForeach(a,a+n,Inc); for(int i = 0;i < n; ++i) cout << a[i] << ","; cout << endl; } return 0;}

代码实现

template 
void MyForeach(T1* startptr,T1* endptr,T2* tempprint){
T1* temp; for(temp = startptr;temp != endptr;temp++) (*tempprint)(*temp); return;}

转载地址:https://love6.blog.csdn.net/article/details/114991278 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C++面向对象程序设计 029:简单的Filter ---- (北大Mooc)
下一篇:C++面向对象程序设计 027:简单的SumArray ---- (北大Mooc) (麻了 今天一天嗯是上课没跑成)

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月30日 07时27分40秒