就是说能不能像
char a = 'd'
int x;
cin>>x;
printf(a*x);
输入 3
输出 3个d
#include<iostream>
using namespace std;
struct myChar {
myChar(char a) {
this->c = a;
}
char c;
};
struct myInt {
myInt(int x) {
this->t = x;
}
int t;
};
string operator *(myChar &c, myInt &n) {
string s;
for (int i = 0; i < n.t; ++i) {
s += c.c;
}
return s;
}
int main() {
myChar a('d');
int temp;
cin >> temp;
myInt x(temp);
printf_s((a*x).c_str());
system("pause");
}
for循环x次,printf里面不换行就好
这样不行
a是char类型,x是整型,输出它们俩的乘积,得到的结果是,a的ascll码乘x
况且你的printf括号里也没有加占位符。
输出应该是这样的:
for(int i=1;i<=x;i++)
printf("%c",a);