我想動畫一個40x20的字符塊,我是cout
-ing。我想用system("cls");
清除控制檯,然後立即出現下一個字符塊。目前下一個街區是打字機風格。控制檯cout動畫 - C++
對我的問題最簡單的答案只是一次有20行40字符oss流cout,而不是打字機的風格。
Main.cpp的:
mazeCreator.cout();
Sleep(5000);
system("cls");
COUT()
void MazeCreator::cout() {
char wallChar = (char) 219;
char pavedChar = (char) 176;
char lightChar = ' ';
char startChar = 'S';
char finishChar = 'F';
char errorChar = '!';
char removedWallChar = 'R';
char landmarkLocationChar = 'L';
ostringstream oss;
for (int row = 0; row < rows; row++) {
oss << " ";
for (int col = 0; col < columns; col++) {
if (mazeArray[row][col] == wall)
oss << wallChar;
else if (mazeArray[row][col] == paved)
oss << pavedChar;
else if (mazeArray[row][col] == light)
oss << lightChar;
else if (mazeArray[row][col] == start)
oss << startChar;
else if (mazeArray[row][col] == finish)
oss << finishChar;
else if (mazeArray[row][col] == removedWall)
oss << removedWallChar;
else if (mazeArray[row][col] == landmarkLocation)
oss << landmarkLocationChar;
else
oss << errorChar;
}
oss << "\n";
}
oss << "\n\n";
cout << oss.str();
}
我認爲這是爲Windows? –
你需要提供更多的細節。 –
你的意思是你可以看到它被繪製?您可以使用緩衝區:http://msdn.microsoft.com/en-us/library/windows/desktop/ms682122(v=vs.85).aspx – chris