#include "Scrabble.h"
#include <iostream>
#include <cstdlib>
#include <stdexcept>
using namespace std;
Scrabble::Scrabble() {
Character *pointer;
pointer = NULL;
reihe = 15;
spalte = 15;
for (int i = 0; i < reihe; i++) {
playground.push_back(vector <Character>());
for (int j = 0; j < spalte; j++) {
playground[i].push_back('a');
}
}
}
void Scrabble::print() {
cout << " ";
for (int i = 0; i < column; i++) {
cout << i << " ";
}
cout << endl;
for (int r = 0; r < row; r++) {
cout << r << " ";
for (int s = 0; s < cloumn; s++) {
cout << playground[r][s] << " ";
}
cout << endl;
}
}`
输出看起来有点奇怪
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
1 a
a
一些建议我如何得到它看起来很正常像:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 a
1 a
2 a
3 a
4 a
5 a
6 a
7 a
8 a
9 a
10 a
11 a
12 a
13 a
14 a
任何建议都会有所帮助,thx
答案 0 :(得分:2)
您的代码段无法编译(例如变量cloumn
),因此我认为这不是您正在测试的代码。
您面临的一个问题是确保使用某个字段。为此,您必须包含<iomanip>
:
void Scrabble::print() {
cout<<" ";
for (int i = 0; i < column; i++) {
cout << setw(2)<<i << " ";
}
cout << endl;
for (int r = 0; r < row; r++) {
cout << setw(2)<< r << " ";
for (int s = 0; s < column; s++) {
cout << setw(2)<< playground[r][s] << " ";
}
cout << endl;
}
}
这里有一个online version(没有上课编译,用于演示目的,因为我不知道Scrabble
的定义