傻了,一直想着设置对齐方式。但也没理解,为什么设置右对齐不可以?
后来才想到通过输出空格就可以实现右对齐了。很简单。
`#include
#include<math.h>
#include
#include
#include<stdio.h>
using namespace std;
struct student {
string num;
string name;
string sex;
int age;
};
int main()
{
int n;
while (cin >> n) {
int x;
x = n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n + (n - 1) * 2-x; j++) {
cout << " ";
}
for (int j = 0; j < x; j++) {
cout << ‘*’;
}
cout << endl;
x += 2;
}
}
system("pause");
return 0;
}`