本文整理汇总了C++中Ostream::width方法的典型用法代码示例。如果您正苦于以下问题:C++ Ostream::width方法的具体用法?C++ Ostream::width怎么用?C++ Ostream::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ostream
的用法示例。
在下文中一共展示了Ostream::width方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: procData
void Foam::PrintTable<KeyType, DataType>::print
(
Ostream& os,
const bool printSum,
const bool printAverage
) const
{
HashTable<HashTable<DataType, label>, KeyType> combinedTable;
List<HashTableData> procData(Pstream::nProcs(), HashTableData());
procData[Pstream::myProcNo()] = table_;
Pstream::gatherList(procData);
if (Pstream::master())
{
label largestKeyLength = 6;
label largestDataLength = 0;
List<label> largestProcSize(Pstream::nProcs(), 0);
forAll(procData, procI)
{
const HashTableData& procIData = procData[procI];
for
(
typename HashTableData::const_iterator iter = procIData.begin();
iter != procIData.end();
++iter
)
{
if (!combinedTable.found(iter.key()))
{
combinedTable.insert
(
iter.key(),
HashTable<DataType, label>()
);
}
HashTable<DataType, label>& key = combinedTable[iter.key()];
key.insert(procI, iter());
for
(
typename HashTable<DataType, label>
::const_iterator dataIter = key.begin();
dataIter != key.end();
++dataIter
)
{
std::ostringstream buf;
buf << dataIter();
largestDataLength = max
(
largestDataLength,
label(buf.str().length())
);
}
std::ostringstream buf;
buf << iter.key();
largestKeyLength = max
(
largestKeyLength,
label(buf.str().length())
);
}
}
os.width(largestKeyLength);
os << nl << indent << tab << "# " << title_.c_str() << endl;
os.width(largestKeyLength);
os << indent << "# Proc";
forAll(procData, procI)
{
os << tab;
os.width(largestDataLength);
os << procI;
}
if (printSum)
{
os << tab;
os.width(largestDataLength);
os << "Sum";
}
if (printAverage)
{
os << tab;
os.width(largestDataLength);
os << "Average";
//.........这里部分代码省略.........
示例2: singleFmt
void Foam::UList<double>::writeNonUniform(Ostream& os) const
{
//Pout<< "width:" << os.width() << endl;
//Pout<< "precision:" << os.precision() << endl;
//Pout<< "fmtflags:" << os.flags() << endl;
//Pout<< "boolalpha:" << (os.flags() & ios_base::boolalpha) << endl;
//Pout<< "showbase:" << (os.flags() & ios_base::showbase) << endl;
//Pout<< "showpoint:" << (os.flags() & ios_base::showpoint) << endl;
//Pout<< "showpos:" << (os.flags() & ios_base::showpos) << endl;
//Pout<< "skipws:" << (os.flags() & ios_base::skipws) << endl;
//Pout<< "unitbuf:" << (os.flags() & ios_base::unitbuf) << endl;
//Pout<< "uppercase:" << (os.flags() & ios_base::uppercase) << endl;
//
//Pout<< "dec:" << (os.flags() & ios_base::showbase) << endl;
//Pout<< "hex:" << (os.flags() & ios_base::hex) << endl;
//Pout<< "oct:" << (os.flags() & ios_base::oct) << endl;
//
//Pout<< "fixed:" << (os.flags() & ios_base::fixed) << endl;
//Pout<< "scientific:" << (os.flags() & ios_base::scientific) << endl;
//
//Pout<< "internal:" << (os.flags() & ios_base::internal) << endl;
//Pout<< "left:" << (os.flags() & ios_base::left) << endl;
//Pout<< "right:" << (os.flags() & ios_base::right) << endl;
const Foam::UList<double>& L = *this;
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST;
if
(
(os.width() == 0)
&& !(os.flags() & ios_base::showbase)
&& !(os.flags() & ios_base::showpoint)
&& !(os.flags() & ios_base::showpos)
&& !(os.flags() & ios_base::unitbuf)
&& !(os.flags() & ios_base::uppercase)
&& !(os.flags() & ios_base::hex)
&& !(os.flags() & ios_base::oct)
&& !(os.flags() & ios_base::fixed)
&& !(os.flags() & ios_base::scientific)
&& !(os.flags() & ios_base::internal)
&& !(os.flags() & ios_base::right)
&& isA<OFstream>(os)
)
{
OFstream& ofs = dynamic_cast<OFstream&>(os);
// Can do optimised
Pout<< "Optimised" << endl;
const string singleFmt("\n%-." + Foam::name(ofs.precision()) + "lg");
string fmt;
for (int i = 0; i < 8; i++)
{
fmt += singleFmt;
}
//Pout<< "Format string:" << fmt << endl;
const char* fmt_ptr = fmt.c_str();
const int bufLen = 4096;
char buf[bufLen];
int free = 0;
label i = 0;
for (label outer = 0; outer < L.size()/8; outer++)
{
const int nFree = bufLen-free;
int n = snprintf
(
&buf[free],
nFree,
fmt_ptr,
L[i],
L[i+1],
L[i+2],
L[i+3],
L[i+4],
L[i+5],
L[i+6],
L[i+7]
);
if (n >= nFree)
{
// Failed. Flush buffer so far
ofs.stdStream().write(buf, free);
free = 0;
// Re-print current entry (assume it succeeds)
n = snprintf
(
&buf[free],
bufLen-free,
fmt_ptr,
L[i],
L[i+1],
L[i+2],
L[i+3],
L[i+4],
L[i+5],
L[i+6],
L[i+7]
//.........这里部分代码省略.........
示例3:
void Foam::functionObjects::writeFile::initStream(Ostream& os) const
{
os.setf(ios_base::scientific, ios_base::floatfield);
os.width(charWidth());
}
示例4: sFmt
void Foam::UList<Foam::Vector<double>>::writeNonUniform(Ostream& os) const
{
//Pout<< "width:" << os.width() << endl;
//Pout<< "precision:" << os.precision() << endl;
//Pout<< "fmtflags:" << os.flags() << endl;
//Pout<< "boolalpha:" << (os.flags() & ios_base::boolalpha) << endl;
//Pout<< "showbase:" << (os.flags() & ios_base::showbase) << endl;
//Pout<< "showpoint:" << (os.flags() & ios_base::showpoint) << endl;
//Pout<< "showpos:" << (os.flags() & ios_base::showpos) << endl;
//Pout<< "skipws:" << (os.flags() & ios_base::skipws) << endl;
//Pout<< "unitbuf:" << (os.flags() & ios_base::unitbuf) << endl;
//Pout<< "uppercase:" << (os.flags() & ios_base::uppercase) << endl;
//
//Pout<< "dec:" << (os.flags() & ios_base::showbase) << endl;
//Pout<< "hex:" << (os.flags() & ios_base::hex) << endl;
//Pout<< "oct:" << (os.flags() & ios_base::oct) << endl;
//
//Pout<< "fixed:" << (os.flags() & ios_base::fixed) << endl;
//Pout<< "scientific:" << (os.flags() & ios_base::scientific) << endl;
//
//Pout<< "internal:" << (os.flags() & ios_base::internal) << endl;
//Pout<< "left:" << (os.flags() & ios_base::left) << endl;
//Pout<< "right:" << (os.flags() & ios_base::right) << endl;
const Foam::UList<Vector<double>>& L = *this;
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST;
if
(
(os.width() == 0)
&& !(os.flags() & ios_base::showbase)
&& !(os.flags() & ios_base::showpoint)
&& !(os.flags() & ios_base::showpos)
&& !(os.flags() & ios_base::unitbuf)
&& !(os.flags() & ios_base::uppercase)
&& !(os.flags() & ios_base::hex)
&& !(os.flags() & ios_base::oct)
&& !(os.flags() & ios_base::fixed)
&& !(os.flags() & ios_base::scientific)
&& !(os.flags() & ios_base::internal)
&& !(os.flags() & ios_base::right)
&& isA<OFstream>(os)
)
{
OFstream& ofs = dynamic_cast<OFstream&>(os);
// Can do optimised
Pout<< "Optimised" << endl;
const string sFmt("%-." + Foam::name(ofs.precision()) + "lg");
string fmt("\n("+sFmt+' '+sFmt+' '+sFmt+')');
Pout<< "Format string:" << fmt << endl;
const char* fmt_ptr = fmt.c_str();
const int bufLen = 4096;
char buf[bufLen];
int free = 0;
forAll(L, i)
{
const Vector<double>& p = L[i];
const int nFree = bufLen-free;
int n = snprintf(&buf[free], nFree, fmt_ptr, p.x(), p.y(), p.z());
if (n >= nFree)
{
ofs.stdStream().write(buf, free);
free = 0;
// Re-print current entry
n = snprintf(&buf[free], bufLen, fmt_ptr, p.x(), p.y(), p.z());
}
free += n;
}
if (free > 0)
{
ofs.stdStream().write(buf, free);
}
}
示例5:
void Foam::functionObjectFile::initStream(Ostream& os) const
{
os.setf(ios_base::scientific, ios_base::floatfield);
// os.precision(IOstream::defaultPrecision());
os.width(charWidth());
}