本文整理汇总了C++中ostream::width方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::width方法的具体用法?C++ ostream::width怎么用?C++ ostream::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ostream
的用法示例。
在下文中一共展示了ostream::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file_it
void file_it(ostream &os, double fo, const double fe[], int n)
{
ios_base::fmtflags initial;
initial = os.setf(ios_base::fixed); // 设置定长显示格式
os.precision(10);
os << "focal length of objective" << fo << endl;
os.setf(ios::showpoint);
os.precision(1);
os.width(12);
os << "f.1, eyepiece";
os.width(15);
os << "magnification" << endl;
for (int i=0; i<n; i++)
{
os.width(12);
os << fe[i];
os.width(15);
os << int(fo/fe[i]+0.5) << endl;
}
os.setf(initial);
}
示例2: DumpDouble
void RecordFactory::DumpDouble(ostream &os, double value,
int width, int decPlaces, bool blankIfZero)
{
double multiplier = pow(10.0, decPlaces);
double outd = value * multiplier;
double frac, integral;
frac = modf(outd, &integral);
int outi = (int)integral;
if (frac >= 0.5)
outi += 1;
if (frac <= -0.5)
outi -= 1;
if (blankIfZero && outi == 0)
{
for (int i = 0; i < width; i++)
os << ' ';
}
else
{
os.width(width);
os << internal << outi;
os.width(0);
}
}
示例3: Draw
void Trajectory::Draw(ostream &os) const {
ios::fmtflags oldflags = os.flags();
os.setf(ios::fixed);
Context all;
os << "time \\ var ";
for(ivmap::const_iterator i=traj.begin();i!=traj.end();++i) {
os.width(5);
os << i->first << " ";
all.AddVar(i->first,2);
}
os << endl;
Instantiation oldv(all,-1);
for(Index ii = Begin(all);!ii.Done();++ii) {
//os << "_____________________________________________________________" << endl;
os << ii.Time() << " ";
for(ivmap::const_iterator i=traj.begin();i!=traj.end();++i) {
if (oldv.Value(i->first)!=ii.Values().Value(i->first)) {
os.width(5);
os << ii.Values().Value(i->first) << " ";
} else {
os << " ";
}
}
os << endl;
oldv = ii.Values();
}
os.flags(oldflags);
}
示例4: min
ostream& __STL_CALL operator<<(ostream& __os,
const basic_string<_CharT,_Traits,_Alloc>& __s)
{
__STL_USING_VENDOR_STD
streambuf* __buf = __os.rdbuf();
if (__buf) {
size_t __n = __s.size();
size_t __pad_len = 0;
const bool __left = (__os.flags() & ios::left) !=0;
const size_t __w = __os.width();
if (__w > 0) {
__n = min(__w, __n);
__pad_len = __w - __n;
}
if (!__left)
__sgi_string_fill(__os, __buf, __pad_len);
const size_t __nwritten = __buf->sputn(__s.data(), __n);
if (__left)
__sgi_string_fill(__os, __buf, __pad_len);
if (__nwritten != __n)
__os.clear(__os.rdstate() | ios::failbit);
__os.width(0);
}
else
__os.clear(__os.rdstate() | ios::badbit);
return __os;
}
示例5: WriteNode
/* ----------------------------------------------------------------------------
Tree genome method overrides
-------------------------------------------------------------------------------
Here we override the built-in methods for the tree class. We can do this
because the tree class is template-ized - when the compiler looks for an
instance of the tree class methods, it finds these so it won't generate an
instance from the templates. You can do this with ANY method of a template
class. Here we do it only for the write method.
The default write operator prints out pointers to the contents of each node.
Here we print out the actual contents of each node. This assumes that the
object in our node has the operator<< defined for it.
---------------------------------------------------------------------------- */
void WriteNode(ostream & os, GANode<int> * n) {
if (!n)
return;
GANodeBASE * node = (GANodeBASE *) n;
os.width(10);
os << ((GANode<int> *) node)->contents << " ";
os.width(10);
if (node->parent)
os << ((GANode<int> *) node->parent)->contents << " ";
else
os << "." << " ";
os.width(10);
if (node->child)
os << ((GANode<int> *) node->child)->contents << " ";
else
os << "." << " ";
os.width(10);
if (node->next)
os << ((GANode<int> *) node->next)->contents << " ";
else
os << "." << " ";
os.width(10);
if (node->prev)
os << ((GANode<int> *) node->prev)->contents << "\n";
else
os << ".\n";
WriteNode(os, (GANode<int> *) node->child);
for (GANodeBASE * tmp = node->next; tmp && tmp != node; tmp = tmp->next) {
os.width(10);
os << ((GANode<int> *) tmp)->contents << " ";
os.width(10);
if (tmp->parent)
os << ((GANode<int> *) tmp->parent)->contents << " ";
else
os << "." << " ";
os.width(10);
if (tmp->child)
os << ((GANode<int> *) tmp->child)->contents << " ";
else
os << "." << " ";
os.width(10);
if (tmp->next)
os << ((GANode<int> *) tmp->next)->contents << " ";
else
os << "." << " ";
os.width(10);
if (tmp->prev)
os << ((GANode<int> *) tmp->prev)->contents << "\n";
else
os << ".\n";
WriteNode(os, (GANode<int> *) tmp->child);
}
}
示例6:
void CCommandLineInterface::CHelpContainer::Output(ostream &Stream)
{
streamsize w = Stream.width();
for (vector<CHelpEntry>::iterator it = Entries.begin(); it != Entries.end(); ++it) {
Stream << "\t";
Stream.width(ShortWidth);
Stream << left << it->Short << "\t";
Stream.width(LongWidth);
Stream << left << it->Long << "\t";
Stream.width(w);
Stream << it->Description << "\n";
}
}
示例7: os
ErrorContext::ErrorContext(ostream &os)
: os(os), passed(0), total(0), lastline(0), skip(false)
{
os << "line: ";
os.width(65);
os.setf(ios::left, ios::adjustfield);
os << "description" << " result" << endl;
os.width(78);
os.fill('~');
os << "~" << endl;
os.fill(' ');
os.setf(ios::right, ios::adjustfield);
}
示例8: FHwrite
// ----------------------------------------------------------------------------------------
// FHwrite
// ----------------------------------------------------------------------------------------
void FileHandler::FHwrite (const age_idx& cur_age, const sex_t& cur_sex, ostream& FILE,
Patch* current_patch, const int& patch_id, const int& nbPatchDigit, const int& position){
unsigned char** seq;
Individual *ind;
int ploidy, nb_locus;
for (unsigned int j = 0, nbInd = current_patch->size(cur_sex, cur_age); j < nbInd; ++j) {
FILE << setfill('0') << setw(nbPatchDigit) << (patch_id+1) << setfill(' ') << " ";
ind = current_patch->get(cur_sex, cur_age, j);
for(int t=0; t<_nb_trait; ++t){ // for multiple instanciations of a trait
ploidy = _trait[t]->get_ploidy();
nb_locus = _trait[t]->get_nb_locus();
seq = (unsigned char**)ind->getTrait(_TTidx[t])->get_sequence();
for(int k = 0; k < nb_locus; ++k) {
for (int l = 0; l < ploidy; ++l) {
FILE.fill('0');
FILE.width(position);
FILE<<(unsigned int)(seq[k][l]+1);
}
FILE<<" ";
}
}
if(_fstat_choice==2){
write_individual_info_to_stream(FILE, ind, cur_age, cur_sex, ' ');
}
FILE << "\n";
}
}
示例9: Gen_Description_and_Type
static void Gen_Description_and_Type(ostream& os, char * Desc_Start, int Prop_type_Index)
{
size_t n = 0;
os << '"' << Desc_Start << "\", ";
os.width(max_Description_length-strlen(Desc_Start)+1);
os << ' ';
os << SGF_property_type_names[Prop_type_Index] << ", ";
os.width(max_Property_type_length+3-strlen(SGF_property_type_names[Prop_type_Index]));
os << ' ';
// Calculate, for next build:
if ((n = strlen(Desc_Start)) > max_Description_length)
max_Description_length = n;
if ((n = strlen(SGF_property_type_names[Prop_type_Index])) > max_Property_type_length)
max_Property_type_length = n;
}
示例10: PrintCurrency
void RecordFactory::PrintCurrency(ostream &os, double value)
{
long double dv = value * 100; // stupid library! divides by 100 for some reason...
// Construct a ostreamb12uf_iterator on cout
typedef std::ostreambuf_iterator<char, std::char_traits<char> > Iter;
Iter begin(os);
// Get a money put facet
const std::money_put<char, Iter> &mp =
std::use_facet<std::money_put<char, Iter> >(std::locale());
ios::fmtflags flgs = os.setf(ios_base::showbase|ios_base::internal);
streamsize orig = os.width(5);
mp.put(begin, false, os, '0', dv);
os.width(orig);
os.flags(flgs);
}
示例11: Gen_Property_note
static void Gen_Property_note(ostream& os, char ch)
{
size_t len;
t_SGF_note theNote=SGF_std;
if (ch == ' ')
os << SGF_note_type_names[theNote=SGF_std] << ", ";
else
if (ch == '*')
os << SGF_note_type_names[theNote=SGFF4_new] << ", ";
else
if (ch == '!')
os << SGF_note_type_names[theNote=SGFF4_changed] << ", ";
else
if (ch == '#')
os << SGF_note_type_names[theNote=SGF_non_std] << ", ";
else
{
std::cout << "***ERROR*** unknown property flag: " << ch << "\n";
exit(1);
}
os.width(max_Property_note_length+1-(len=strlen(SGF_note_type_names[theNote])));
os << ' ';
if (len > max_Property_note_length)
max_Property_note_length = len;
}
示例12: DisplayBeliefs
void POCMAN::DisplayBeliefs(const BELIEF_STATE& beliefState,
ostream& ostr) const
{
GRID<int> counts(Maze.GetXSize(), Maze.GetYSize());
counts.SetAllValues(0);
for (int i = 0; i < beliefState.GetNumSamples(); i++)
{
const POCMAN_STATE* pocstate =
safe_cast<const POCMAN_STATE*>(
beliefState.GetSample(i));
for (int g = 0; g < NumGhosts; g++)
counts(pocstate->GhostPos[g])++;
}
for (int y = Maze.GetYSize() - 1; y >= 0; y--)
{
for (int x = 0; x < Maze.GetXSize(); x++)
{
ostr.width(6);
ostr.precision(2);
ostr << fixed << (double) counts(x, y) / beliefState.GetNumSamples();
}
ostr << endl;
}
}
示例13: print_braille
void print_braille(const char* plaintext, ostream& output){
int size = strlen(plaintext)*6;
char temp[20];
char out[512];
encode(plaintext,out);
if(encode_character(*plaintext,temp)==12)
size += 6;
for(int i = 0; i < 3; i++){
cout << " ";
for(int j = 0; j<(size/6);j++){
output << out[(j*6)+i] << out[(j*6)+3+i] << " ";
}
output << endl;
}
if(encode_character(*plaintext,temp)==12)
output << " ";
output << setiosflags (ios::left );
while(*plaintext != '\0'){
output.width(3);
output << *plaintext;
++plaintext;
}
output << endl;
}
示例14: OutShort
void CNodeStats::OutShort(ostream& os) const {
double nNodes=Nodes();
double t=Seconds();
os.width(4);
if (nNodes<1E4)
os << int(nNodes) << " ";
else if (nNodes<1E7)
os << int(nNodes*1e-3) << "k";
else if (nNodes<1E10)
os << int(nNodes*1e-6) << "M";
else
os << int(nNodes*1e-9) << "G";
os << "n/";
std::streamsize precision=os.precision(3);
auto flags=os.setf(ios::fixed, ios::floatfield);
int knps=int(nNodes/t*1E-3);
os << t << "s = " << std::setw(4) << knps << "kn/s; ";
double dUspn=t/nNodes*1e6;
os.precision(2);
if (dUspn>=100)
os << "**.** us/n";
else
os << setw(5) << dUspn << " us/n";
os.precision(precision);
os.setf(flags);
}
示例15: StreamTimer
//*****************************************************************************
void PerformanceTimer::StreamTimer(ostream & stream) const
{
//Downshift to double as HP can't stream a long double. Should still provide
//the necessary resolution (overflow is very unlikely)
double Time = (double)(Ticks() / TicksPerSec());
stream.width(12);
stream << Time << " seconds" << "\t\t";
Time = (double)(TotalTicks() / TicksPerSec());
stream.width(12);
stream << Time << " seconds (cumulative)" << "\t\t" << Invocations() << " Runs";
if (getIsRunning())
{
stream << ",RUNNING";
}
}