【问题描述】编写函数,重复打印给定字符n次,n由输入数字确定。
【输入形式】输入一个字符,以及字符需要重复打印的次数
【输出形式】提示信息:please input a char and the times:
【样例输入】a 5
【样例输出】please input a char and the times:
aaaaa
//编写函数,重复打印给定字符n次,n由输入数字确定
#include<iostream>
#include<vector>
using namespace std;
int main()
{
char a;//单个字符
int time;//次数
cout<<"please input a char and the times:"<<endl;
cin>>a>>time;
vector<char>v;
for(;time>0;--time)
{
v.push_back(a);//压入time个字符
}
for(vector<char>::size_type t= 0;t<v.size();++t)
{
cout<<v[t];//输出time个字符
}
return 0;
}