我一直在努力與這幾個小時,但我需要幫助格式化一些輸出。基本上,我有一個二維陣列arr
,我想在3×70組以進行打印,即C++ - 列格式
aaaaaa ... a //Columns 1-70
bbbbbb ... b //Columns 1-70
cccccc ... c //Columns 1-70
//newline
//newline
//newline
aaaaaa ... a //Columns 1-70
bbbbbb ... b //Columns 1-70
cccccc ... c //Columns 1-70
//and so on like that until all of top, mid, and bot is printed out
aaaa....a
其中對應於arr[0]
,bbbbb....b
對應於arr[1]
,和cccc...c
對應於arr[2]
。
另一部分是arr
對應於三個一維數組top
,mid
和bot
。正如您可以猜到的,aaaa...aaa
是top
,bbbb...bbb
中的值是mid
中的值,而ccc....ccc
是bot
中的值。 top
,mid
和bot
的長度全部相同,因此一個字段length
已被分配給該值。
我當前的代碼是(不包括進口):
string alignToString;
stringstream out;
char arr[3][70];
for (int column = 1; column <= length; ++column)
{
out << top[column - 1];
if (column % 70 == 0)
{
out << endl;
for (int column = 1; column < 70; ++column)
{
}
}
arr[0][column] = top[column - 1];
arr[1][column] = mid[column - 1];
arr[2][column] = bot[column - 1];
if (column % 70 == 0)
{
break;
}
//TODO: output out.str();
}
此代碼不能正常工作,效果顯着。我有想法,也許我可以輸出每列三個一組,並且一旦列%70 = 0,我會添加換行符,但我似乎無法弄清楚。如果有人能幫助我解決這個問題,或者爲這個問題提供更好的解決方案,我將不勝感激。先謝謝你。
我不知道top,mid,bot的作用是什麼。其實我不明白你想做什麼。你也沒有寫出當前的輸出是什麼,它與你想要的不同。如果你真的想得到答案,你應該改寫你的問題。 – Silicomancer 2014-12-05 08:03:04