我一直在試圖格式化輸出到控制檯最長的時間,沒有真正發生。我一直在嘗試儘可能多地使用iomanip
和我的功能,以及ofstream&
的功能。格式化C++控制檯輸出
void list::displayByName(ostream& out) const
{
node *current_node = headByName;
// I have these outside the loop so I dont write it everytime.
out << "Name\t\t" << "\tLocation" << "\tRating " << "Acre" << endl;
out << "----\t\t" << "\t--------" << "\t------ " << "----" << endl;
while (current_node)
{
out << current_node->item.getName()// equivalent tabs dont work?
<< current_node->item.getLocation()
<< current_node->item.getAcres()
<< current_node->item.getRating()
<< endl;
current_node = current_node->nextByName;
}
// The equivalent tabs do not work because I am writing names,
// each of different length to the console. That explains why they
// are not all evenly spaced apart.
}
他們是什麼我可以用它來讓它們彼此正確對齊?我調用的函數是不言自明的,並且所有不同的長度,所以不能很好地對齊。
我已經試過iomanip
中的一切。
+1標準IO操縱(運輸及工務局局長和人),一爲定義自定義了iomanip,-1爲Excel – outis 2009-09-20 01:04:26
而且你還可以限制字符串的大小要打印,以防萬一你有大字符串(如完整名稱) – Vargas 2009-09-20 01:28:41