打印效果:
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main(){
int j = 0;
vector<vector<int> >vec(9, vector<int>(0));
for (int i = 0; i < 9; i++){
for (j = 0; j <= i+1; j++){
vec[i].push_back((i+1)*(j+1));
}
}
for (int i = 0; i < vec.size(); i++){
for (int j = 0; j <= i; j++){
//使用setw(n) 进行格式控制
cout << (i+1) << "*" << (j+1) << "=" << setw(2) << vec[i][j]<< " ";
//printf("%d*%d=%2d ", (i+1),(j+1),vec[i][j]);
}
cout << endl;
}
return 0;
}