1. Field Width Setting field width is very simple. For each variable, simply precede it with "setw(n)". Like this:
#includeNotice how "setw(n)" controls the field width, so each number is printed inside a field that stays the same width regardless of the width of the number itself.#include iomanip using namespace std; int main() { const int max = 12; const int width = 6; for(int row = 1;row <= max;row++) { for(int col = 1;col <= max;col++) { cout << setw(width) << row * col; } cout << endl; } return 0; }
沒有留言:
張貼留言