#include <iostream>
#include <string>
#include <vector>
using namespace std;
void Print(int n)
{
cout << n * n << ",";
}
class MyPrint
{
public:
void operator()(const string& s)
{
cout << s << ",";
}
};
void my_for_each(int i[], int* end, void (*p)(int))
{
int* q;
q = &i[0];
while (q != end)
{
p(*q);
q++;
}
}
void my_for_each(string& str1, string& str2, )
{
string* str;
str = &str1;
while (str != &str2)
{
str++;
MyPrint(*str);
}
}
int main()
{
int t;
int a[5];
vector<string> vt;
cin >> t;
while (t--)
{
vt.clear();
for (int i = 0;i < 5; ++i)
cin >> a[i];
for (int i = 0;i < 5; ++i)
{
string s;
cin >> s;
vt.push_back(s);
}
my_for_each(a, a + 5, Print);
cout << endl;
my_for_each(vt.begin(), vt.end(), MyPrint());
cout << endl;
}
return 0;
}
提示,调用函数,参数必须匹配,vector::iterator 不是string