【发布时间】:2020-08-04 13:03:34
【问题描述】:
我的代码如下所示
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x;
char chars = '*';
cin >> x;
for (int i=1; i<=x; i++){
cout << chars * i << endl;
}
cout << "\n\n";
system("pause");
return 0;
}
它编译成功但是,当我运行它时,我只是显示这个
1
42
我想打印 ('*') x 次,请有人帮助我
【问题讨论】:
-
char被视为int。 -
cout << string(x, '*') << "\n";