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); }
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); } }
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); }
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; }
/* ---------------------------------------------------------------------------- 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); } }
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"; } }
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); }
// ---------------------------------------------------------------------------------------- // 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"; } }
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; }
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); }
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; }
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; } }
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; }
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); }
//***************************************************************************** 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"; } }
void ast_node::output_at_level(ostream& stream,int level) const { stream.width(4); stream << _lineno << ' '; for (int i = 0;i < level;++i) stream.put('\t'); output_impl(stream,level+1); }
MVS_API void reset(ostream& os) noexcept { os.clear(); os.fill(os.widen(' ')); os.flags(ios_base::skipws | ios_base::dec); os.precision(6); os.width(0); };
static void printStep(int step, double x, double dx, double f_of_x, ostream& os) { int w = os.width(); int p = os.precision(); ios::fmtflags f = os.flags(); os.setf(ios::right, ios::adjustfield); os << " " << setw(4) << step << " "; os.setf(ios::left, ios::adjustfield); os << setprecision(14) << setw(20) << x << " " << setw(20) << dx << " " << setw(20) << f_of_x << endl; os.width(w); os.precision(p); os.setf(f); }
void Dof::print(ostream &out) const{ out << " EqnNum = "; out.width(6); out << _eqn_number; if (_active) { out << " Active, "; } else { out << " Not Active, "; } out << " Value = "; out.setf(ios::scientific); out.precision(3); out.width(11); out << _value; }
void Othello::AfficherEnTete(ostream & output, int maxColonnes) const { output << " "; for (int i = 0; i < maxColonnes; ++i) { output << " "; output.width(2); output << i; } output << endl; }
void file_it(ostream&os,double fo,const double fe[],int n) { ios_base::fmtflags initial; initial = os.setf(ios_base::fixed); // save initial formatting state os.precision(0); 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); }
void file_it(ostream & os, double fo, const double fe[], int n){ ios_base::fmtflags initial; initial = os.setf(ios_base::fixed); //сохранение исходного состояния форматирования os.precision(0); os << "Фокусное расстояние объектива: " << fo << " mm\n"; os.setf(ios::showpoint); os.precision(1); os.width(12); os << "коэффициент увеличения"; os.width(15); os << "окуляра" << 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); // восстановление исходного состояния форматирования }
// --------------------------------------------------------------------------- // ^FUNCTION: Options::usage - print usage // // ^SYNOPSIS: // void Options::usage(os, positionals) // // ^PARAMETERS: // ostream & os -- where to print the usage // char * positionals -- command-line syntax for any positional args // // ^DESCRIPTION: // Print command-usage (using either option or long-option syntax) on os. // // ^REQUIREMENTS: // os should correspond to an open output file. // // ^SIDE-EFFECTS: // Prints on os // // ^RETURN-VALUE: // None. // // ^ALGORITHM: // Print usage on os, wrapping long lines where necessary. // ^^------------------------------------------------------------------------- void Options::usage(ostream & os, const char * positionals) const { #ifdef NO_USAGE return; #else const char * const * optv = optvec; unsigned cols = 79; int first, nloop; char buf[256] ; if ((optv == NULL) || (! *optv)) return; // print first portion "usage: progname" os << "usage: " << cmdname ; unsigned ll = strlen(cmdname) + 7; // save the current length so we know how much space to skip for // subsequent lines. // unsigned margin = ll + 1; // print the options and the positional arguments for (nloop = 0, first = 1 ; !nloop ; optv++, first = 0) { unsigned len; OptionSpec optspec = *optv; // figure out how wide this parameter is (for printing) if (! *optv) { len = strlen(positionals); ++nloop; // terminate this loop } else { if (optspec.isHiddenOpt()) continue; len = optspec.Format(buf, optctrls); } // Will this fit? if ((ll + len + 1) > (cols - first)) { os << '\n' ; // No - start a new line; #ifdef USE_STDIO for (int _i_ = 0; _i_ < margin; ++_i_) os << " "; #else os.width(margin); os << "" ; #endif ll = margin; } else { os << ' ' ; // Yes - just throw in a space ++ll; } ll += len; os << ((nloop) ? positionals : buf) ; }// for each ad os << endl ; #endif /* NO_USAGE */ }
void PeridigmNS::Timer::printTimingData(ostream &out){ int count = (int)( timers.size() ); vector<string> names(count); vector<double> times(count); vector<double> minTimes(count); vector<double> maxTimes(count); vector<double> totalTimes(count); int i = 0; for(map<string, TimeKeeper>::reverse_iterator it=timers.rbegin() ; it!=timers.rend() ; it++){ names[i] = it->first; times[i] = it->second.getElapsedTime(); i++; } Teuchos::RCP<const Teuchos::Comm<int> > teuchosComm = Teuchos::createMpiComm<int>(Teuchos::opaqueWrapper<MPI_Comm>(MPI_COMM_WORLD)); Teuchos::reduceAll<int, double>(*teuchosComm,Teuchos::REDUCE_MIN,count,×[0], &minTimes[0]); Teuchos::reduceAll<int, double>(*teuchosComm,Teuchos::REDUCE_MAX,count,×[0], &maxTimes[0]); Teuchos::reduceAll<int, double>(*teuchosComm,Teuchos::REDUCE_SUM,count,×[0], &totalTimes[0]); unsigned int nameLength = 0; for(unsigned int i=0 ; i<names.size() ; ++i) if(names[i].size() > nameLength) nameLength = names[i].size(); int indent = 15; int nProc = teuchosComm->getSize(); if(nProc > 1 && teuchosComm->getRank() == 0){ out << "Wallclock Time (seconds):" << endl; out << " "; out.width(nameLength + 17); out << "Min"; out.width(indent); out << right << "Max"; out.width(indent); out << right << "Ave"; out << endl; out.precision(2); for(unsigned int i=0 ; i<names.size() ; ++i){ out << " "; out.width(nameLength + 2); out << left << names[i]; out.width(indent); out << right << minTimes[i]; out.width(indent); out << right << maxTimes[i]; out.width(indent); out << right << totalTimes[i]/nProc; out << endl; } out << endl; } else if(nProc == 1){ out << "Wallclock Time (seconds):" << endl; out.precision(2); for(unsigned int i=0 ; i<names.size() ; ++i){ out << " "; out.width(nameLength + 2); out << left << names[i]; out.width(indent); out << right << minTimes[i]; out << endl; } out << endl; } }
static void Gen_Qualifier(ostream& os, int Prop_qual_Index) { size_t n = 0; os << SGF_qualifier_type_names[Prop_qual_Index] << ", "; os.width(max_Property_type_qualifier_length+3-(n=strlen(SGF_qualifier_type_names[Prop_qual_Index]))); os << ' '; if (max_Property_type_qualifier_length < n) max_Property_type_qualifier_length = n; }
static void Gen_Value(ostream& os, int Prop_value_Index) { size_t n = 0; os << SGF_value_type_names[Prop_value_Index]; os.width(max_Property_value_length+3 -( n=strlen( SGF_value_type_names[Prop_value_Index] ) ) ); os << ' '; if (max_Property_value_length < n) max_Property_value_length = n; }
void numVector::print(ostream &out) const { for(int i=0; i<_n_rows; i++){ out << "Row " << i << " "; out.setf(ios::scientific); out.precision(3); out.width(12); out << _coeff[i] << endl; } out << endl; }
void ProgramOptions::showvalues(ostream & outstr, bool withdescription) const { for (unsigned int i = 0; i < optcount; i++) { (void) outstr.width(20); outstr << alloptions[i]->flag << "\t : " << alloptions[i]->gettypename() << "\t : "; if (withdescription) outstr << alloptions[i]->description << "\t : "; (void) alloptions[i]->writevalue(outstr); outstr << endl; } }
void numMatrix::printCompact(ostream &out){ for(int i=0; i<_n_rows; i++){ for(int j=0; j<_n_cols; j++){ out.setf(ios::scientific); out.precision(3); out.width(12); out << _coeff[i][j]; } out << endl; } out << endl; }
// ---------------------------------------------------------------------------------------- // print_legend // ---------------------------------------------------------------------------------------- void StatHandlerBase::print_legend(ostream& FH, unsigned int order) { STAT_IT IT = _stats.begin(); for(int i=1; IT != _stats.end(); ++i, ++IT) { if( (*IT)->getOrdering() & order) { FH.width(20); FH.setf(ios::left,ios::adjustfield); FH<<(*IT)->getName(); FH<<": " << (*IT)->getTitle() << "\n"; } } }