井的Ive試圖編輯的陣列的元件,以便讓我們假設我們有一個二維數組編輯二維數組內的一系列元素?
所以 2D陣列9×9;
for(... ... ... ++)
{
for(.. ... ...++){}
}
可以說,該代碼將使用另一組的for循環來顯示2D陣列它的一個簡單陣列沒有任何幻想
00000000
00000000
00000000...
所以,如果我想顯示從元素的E [1 ] [0]到[2] [3]我該怎麼做?
00000000
eeeeeeee
eeee0000
00000000
什麼,我腦子裏想的是一樣的東西,而(X < Y) {陣列[X ++] [Y];} 但這個想法似乎沒有工作。 很樂意接受任何幫助。 thx
for(int i=0; i<9; i++) //This loops on the rows.
{
for(int j=0; j<9; j++) //This loops on the columns
{
board[i][j] = grid; // set the array to the char on grid '0'.
}
}
board[s_col][s_row] = 'Z';
while(s_col < e_col)//s_col is the start of the rows and columns
//{
//if(s_col != e_col)
{
++s_col;
board[s_col][s_row];
}
//}
//cout << board[s_col][s_row++] <<endl;
// display the array
for(int i=0; i<9; i++) //This loops on the rows.
{
for(int j=0; j<9; j++) //This loops on the columns
{
cout << board[i][j] << " ";
}
cout << endl;
}
對於初學者,您可能希望讓代碼更加具體!不過,我已經可以評論的一件事是,C++更喜歡preincrement而不是postincrement,儘管它的名字(儘管它對你的問題無關緊要)。 –
thx kuhl。我有++ s_col;我沒有使用它; p。至於更多的代碼在這裏是新的,所以每行之間使用8個空格是痛苦的。如果有一種簡單的方法,我不知道它 – user2316289
你只需要開始每行代碼4空格,然後正常縮進(我不知道什麼標籤做,但你不應該使用標籤)。任何中途體面的編輯器都可以讓你在每行前面插入4個空格,例如,我使用':%s/^'/''''''''''''。 –