【发布时间】:2010-11-29 19:21:20
【问题描述】:
我一直在尝试将输出格式化到控制台的最长时间,但实际上并没有发生任何事情。我一直在尝试尽可能多地使用iomanip 和ofstream& out 函数。
void list::displayByName(ostream& out) const
{
node *current_node = headByName;
// I have these outside the loop so I don't write it every time.
out << "Name\t\t" << "\tLocation" << "\tRating " << "Acre" << endl;
out << "----\t\t" << "\t--------" << "\t------ " << "----" << endl;
while (current_node)
{
out << current_node->item.getName() // Equivalent tabs don't 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 中的所有内容。
【问题讨论】:
标签: c++ formatting