本文整理汇总了C++中ostream::setf方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::setf方法的具体用法?C++ ostream::setf怎么用?C++ ostream::setf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ostream
的用法示例。
在下文中一共展示了ostream::setf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2:
void
Rule::
print(ostream& os)
{
stringstream ss;
ss<<prob;
string temp;
ss>>temp;
//os.setf(
os.precision(5);
os.setf(ios::fixed,ios::floatfield);
os<<prob<<" ";
//if(temp.length()<8)
// os<<"\t";
os<<left<<" --> "<<right<<endl;
}
示例3: print
void numMatrix::print(ostream &out){
for(int i=0; i<_n_rows; i++){
out << "Row " << i << endl;
for(int j=0; j<_n_cols; j++){
out.setf(ios::scientific);
out.precision(4);
out.width(13);
out << _coeff[i][j];
if((j+1)%6 == 0){
out << endl;
}
}
out << endl;
out << endl;
}
}
示例4: PrintParticleData
void PrintParticleData(ostream &out, const Ipp32f particledata[][8], const int startrow,
const int endrow, const int framenumber, const int stacknumber)
{
//totalrows is (basically) number of particles (one for each row); can be a very large number
out.setf(ios::fixed);
out.precision(1);
for(int j = startrow; j < endrow; j++) {
out << stacknumber << "\t" << framenumber + 1 << "\t";
out << particledata[j][1] << "\t"; //x-position
out << particledata[j][2] << "\t"; //y-position
out << particledata[j][5] << "\t"; //total mass
out << sqrt(particledata[j][6]); //radius of gyration
out << endl;
}
out.precision(5);
}
示例5: print
void DataPoint::print(ostream& os) {
os.setf(ios::fixed, ios::floatfield);
os.precision(4);
os.fill('0'); // Pad on left with '0'
os << setw(2) << getTime().tm_mon << '\\'
<< setw(2) << getTime().tm_mday << '\\'
<< setw(2) << getTime().tm_year << ' '
<< setw(2) << getTime().tm_hour << ':'
<< setw(2) << getTime().tm_min << ':'
<< setw(2) << getTime().tm_sec;
os.fill(' '); // Pad on left with ' '
os << " Lat:" << setw(9) << getLatitude()
<< ", Long:" << setw(9) << getLongitude()
<< ", depth:" << setw(9) << getDepth()
<< ", temp:" << setw(9) << getTemperature()
<< endl;
} ///:~
示例6: print
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;
}
示例7: printSimplexTable
//prints the results into readable form
void simplex::printSimplexTable(ostream& out, Data* data) {
out.setf(ios::fixed);
out.precision(3);
int row = data->system.size();
int col = data->system[0].size();
out.width(N);
out << "Base";
out.width(N);
out << "Plan";
for (int j = 0; j < col; j++) {
out.width(N - 1);
out << "x";
out << j + 1;
}
out << endl;
for (int i = 0; i < row; i++) {
out.width(N - 1);
out << "x";
out << data->base[i];
out.width(N);
out << data->freeMembers[i];
for (int j = 0; j < col; j++) {
out.width(N);
out << data->system[i][j];
}
out << endl;
}
out.width(N);
out << "F";
out.width(N);
out <<data-> max;
int a = data->coefficients.size();
for (int i = 0; i < a; i++) {
out.width(N);
out << data->coefficients[i];
}
out << endl << endl;
}
示例8: Print
/*-------------------------------------------------------------------------------
Class: Util
Method: Print
Description: Prints output to a stream.
Parameters: ostream& out : in : Stream where to write
const string& aMsg : in : Message to output
const VerboseLevel aLevel : in : Verbose level of message
const long aCode : in : Possible error code if != 0
Return Values: None
Errors/Exceptions: None
-------------------------------------------------------------------------------*/
void Util::Print(ostream& out,
const string& aMsg,
const VerboseLevel aLevel,
const long aCode)
{
#ifdef ENABLE_LOG_SYNC
iCritical.Lock();
#endif
if (aLevel <= iVerbose)
{
if (iTimestamp)
{
char timestamp[128];
_strdate(timestamp);
char tmp[16];
_strtime(tmp);
strcat(timestamp, " ");
strcat(timestamp, tmp);
struct _timeb tb;
_ftime(&tb);
sprintf(tmp, ".%03d", tb.millitm);
strcat(timestamp, tmp);
out << "[" << timestamp << "] ";
}
out << aMsg;
//if (aLevel == debug)
{
OutputDebugString(aMsg.c_str());
OutputDebugString("\r\n");
}
if (aCode != 0)
{
out.setf(ios_base::hex, ios_base::basefield);
out << " (error: 0x" << aCode << ")";
}
out << endl;
}
#ifdef ENABLE_LOG_SYNC
iCritical.Unlock();
#endif
}
示例9: process
void process(istream &input, ostream &output)
{
int bottles, level, n;
input >> bottles >> level >> n;
int row = 0;
int first = 1;
while (first + row + 1 <= n)
{
++row;
first += row;
}
cache.clear();
double value = get_value(level, row, n - first, 750.0 * bottles);
output.setf(ios_base::fixed, ios_base::floatfield);
output.precision(7);
output << ' ' << min(250.0, value) << '\n';
}
示例10: NavigationParameters
void ImagerDoc::NavigationParameters(ostream & out){
out.setf(std::ios::left | std::ios::showpoint | std::ios::fixed);
out << std::setw(19) << Iscan.imcStatus() << "imc " << "\tIMC status (1 == on)\n";
out << std::setw(19) << W_pix_of_frame << "x1 " << "\tWestern-most visible pixel in current frame\n";
out << std::setw(19) << E_pix_of_frame << "x2 " << "\tEastern-most visible pixel in current frame\n";
out << std::setw(19) << N_line_of_frame << "y1 " << "\tNorthern-most visible pixel in current frame\n";
out << std::setw(19) << S_line_of_frame << "y2 " << "\tSouthern-most visible pixel in current frame\n";
out << std::setw(19) << pix_of_zero_az << "x_zero " << "\tpixel of zero azimuth\n";
out << std::setw(19) << line_of_zero_elev << "y_zero " << "\tline of zero elevation\n";
out << std::setw(19) << (double)ReferenceLongitude << "ref_lon " << "\tReference Longitude (positive east, radians) \n";
out << std::setw(19) << (double)ReferenceRadialDistance << "ref_dist " << "\tReference Radial Distance from nominal (kilometers [km]) \n";
out << std::setw(19) << (double)ReferenceLatitude << "ref_lat " << "\tReference Latitude (positive north, radians)\n";
out << std::setw(19) << (double)ReferenceOrbitYaw << "ref_yaw " << "\tReference Orbit Yaw (radians) \n";
out << std::setw(19) << (double)ReferenceAttitudeRoll << "att_roll " << "\tReference Attitude Roll (radians) \n";
out << std::setw(19) << (double)ReferenceAttitudePitch << "att_pitch " << "\tReference Attitude Pitch (radians) \n";
out << std::setw(19) << (double)ReferenceAttitudeYaw << "att_yaw " << "\tReference Attitude Yaw (radians) \n";
out << "\n\n";
}
示例11: formatAndAppend
void PatternConverter::formatAndAppend(ostream& output, const InternalLoggingEvent& loggingEvent)
{
string str;
convert(str, loggingEvent);
std::size_t len = str.length();
if(len > _maxLen)
output << str.substr(len - _maxLen);
else if(static_cast<int>(len) < _minLen)
{
std::ios_base::fmtflags const original_flags = output.flags();
char const fill = output.fill(' ');
output.setf(_leftAlign ? std::ios_base::left : std::ios_base::right,
std::ios_base::adjustfield);
output.width(_minLen);
output << str;
output.fill(fill);
output.flags(original_flags);
}
else
output << str;
}
示例12: timeDisplay
void CNavDataElement::timeDisplay( ostream & os, const CommonTime& t )
{
os.setf(ios::dec, ios::basefield);
// Convert to CommonTime struct from GPS wk,SOW to M/D/Y, H:M:S.
GPSWeekSecond dummyTime;
dummyTime = GPSWeekSecond(t);
os << setw(4) << dummyTime.week << "(";
os << setw(4) << (dummyTime.week & 0x03FF) << ") ";
os << setw(6) << setfill(' ') << dummyTime.sow << " ";
switch (dummyTime.getDayOfWeek())
{
case 0: os << "Sun-0"; break;
case 1: os << "Mon-1"; break;
case 2: os << "Tue-2"; break;
case 3: os << "Wed-3"; break;
case 4: os << "Thu-4"; break;
case 5: os << "Fri-5"; break;
case 6: os << "Sat-6"; break;
default: break;
}
os << printTime(t," %3j %5.0s %02m/%02d/%04Y %02H:%02M:%02S");
}
示例13: dump
void CNAVEphemeris :: dump(ostream& s) const
throw()
{
s.setf(ios::fixed, ios::floatfield);
s.setf(ios::right, ios::adjustfield);
s.setf(ios::uppercase);
s.precision(0);
s.fill(' ');
s << "****************************************************************"
<< "************" << endl
<< "CNAV Message Types 10 and 11" << endl
<< endl
<< "PRN : " << setw(2) << PRNID << " "
<< "System : " << satSys << " "
<< "Carrier: " << ObsID::cbDesc[obsID.band] << " "
<< "Code: " << ObsID::tcDesc[obsID.code] << endl << endl;
s << " Week SOW DOW UTD SOD"
<< " MM/DD/YYYY HH:MM:SS\n";
s << "Transmit Time: ";
timeDisplay(s, getTransmitTime());
s << endl;
s << "Time of Predict:";
timeDisplay(s, getTimeOfPrediction());
s << endl;
s << endl
<< " ACCURACY PARAMETERS"
<< endl
<< endl
<< "URAoe index: " << setw(4) << orbit.getURAoe() << endl;
s.setf(ios::scientific, ios::floatfield);
s.precision(11);
s << endl
<< " SIGNAL PARAMETERS"
<< endl
<< endl
<< "L1 Health bit: " << setw(2) << L1Health << endl
<< "L2 Health bit: " << setw(2) << L2Health << endl
<< "L5 Health bit: " << setw(2) << L5Health << endl
<< setfill(' ') << endl;
s << endl
<< " ORBIT PARAMETERS"
<< endl
<< endl
<< "Semi-major axis: " << setw(18) << orbit.getAhalf() << " m**.5" << endl
<< "Motion correction: " << setw(18) << orbit.getDn() << " rad/sec"
<< endl
<< "Eccentricity: " << setw(18) << orbit.getEcc() << endl
<< "Arg of perigee: " << setw(18) << orbit.getW() << " rad" << endl
<< "Mean anomaly at epoch: " << setw(18) << orbit.getM0() << " rad" << endl
<< "Right ascension: " << setw(18) << orbit.getOmega0() << " rad "
<< setw(18) << orbit.getOmegaDot() << " rad/sec" << endl
<< "Inclination: " << setw(18) << orbit.getI0() << " rad "
<< setw(18) << orbit.getIDot() << " rad/sec" << endl;
s << endl
<< " HARMONIC CORRECTIONS"
<< endl
<< endl
<< "Radial Sine: " << setw(18) << orbit.getCrs() << " m Cosine: "
<< setw(18) << orbit.getCrc() << " m" << endl
<< "Inclination Sine: " << setw(18) << orbit.getCis() << " rad Cosine: "
<< setw(18) << orbit.getCic() << " rad" << endl
<< "In-track Sine: " << setw(18) << orbit.getCus() << " rad Cosine: "
<< setw(18) << orbit.getCuc() << " rad" << endl;
s << "****************************************************************"
<< "************" << endl;
} // end of CNAVEphemeris::dump()
示例14: FractionalToCartesian
// =======================================================
// * Generate a listing of cartesian coordinates for a
// cell propogated through (i,j,k) translations. The
// coordinates are centered on the origin.
void
CrystalCell::Propogate(
unsigned i,
unsigned j,
unsigned k,
ostream& os,
unsigned opts
)
{
TVector3D xform = { 0.0 , 0.0 , 0.0 };
TPoint3D pt;
unsigned li,lj,lk,bb;
ios_base::fmtflags savedFlags = os.flags();
ANSRDB* periodicTable = ANSRDB::DefaultANSRDB();
// Vector-transform to be used on each point such
// that we center the generated lattice at the
// origin:
if (opts == kCrystalCellPropogateCentered) {
Vector3D_ScaledSum(&xform,(double)i,&av[0],&xform);
Vector3D_ScaledSum(&xform,(double)j,&av[1],&xform);
Vector3D_ScaledSum(&xform,(double)k,&av[2],&xform);
Vector3D_Scalar(&xform,-0.5,&xform);
}
// Simply loop and generate points:
os.setf(ios::fixed);
for ( li = 0 ; li < i ; li++ ) {
for ( lj = 0 ; lj < j ; lj++ ) {
for ( lk = 0 ; lk < k ; lk++ ) {
for ( bb = 0 ; bb < basisCount ; bb++ ) {
pt = basis[bb].atomPosition;
if (li) pt.x += (double)li;
if (lj) pt.y += (double)lj;
if (lk) pt.z += (double)lk;
pt = FractionalToCartesian(pt);
Vector3D_Sum(&pt,&xform,&pt);
TElementSymbol symbol = periodicTable->LookupSymbolForNumber(basis[bb].atomicNumber);
if (symbol == kANSRInvalidSymbol) {
os.setf(ios::left);
os << " " << setw(3) << basis[bb].atomicNumber << " ";
os.unsetf(ios::left);
os << setprecision(6) << setw(12) << pt.x << ' ';
os << setprecision(6) << setw(12) << pt.y << ' ';
os << setprecision(6) << setw(12) << pt.z << endl;
} else {
os.setf(ios::left);
os << " " << setw(3) << (char*)&symbol << " ";
os.unsetf(ios::left);
os << setprecision(6) << setw(12) << pt.x << ' ';
os << setprecision(6) << setw(12) << pt.y << ' ';
os << setprecision(6) << setw(12) << pt.z << endl;
}
}
}
}
}
os.setf(savedFlags);
}
示例15: streamData
void Agent::streamData(ostream& out,
std::set<string> &aFilter,
bool current,
unsigned int aInterval,
uint64_t start,
unsigned int count,
unsigned int aHeartbeat
)
{
// Create header
string boundary = md5(intToString(time(NULL)));
ofstream log;
if (mLogStreamData)
{
string filename = "Stream_" + getCurrentTime(LOCAL) + "_" +
int64ToString((uint64_t) dlib::get_thread_id()) + ".log";
log.open(filename.c_str());
}
out << "HTTP/1.1 200 OK\r\n"
"Date: " << getCurrentTime(HUM_READ) << "\r\n"
"Server: MTConnectAgent\r\n"
"Expires: -1\r\n"
"Connection: close\r\n"
"Cache-Control: private, max-age=0\r\n"
"Content-Type: multipart/x-mixed-replace;boundary=" << boundary << "\r\n"
"Transfer-Encoding: chunked\r\n\r\n";
// This object will automatically clean up all the observer from the
// signalers in an exception proof manor.
ChangeObserver observer;
// Add observers
std::set<string>::iterator iter;
for (iter = aFilter.begin(); iter != aFilter.end(); ++iter)
mDataItemMap[*iter]->addObserver(&observer);
uint64_t interMicros = aInterval * 1000;
uint64_t firstSeq = getFirstSequence();
if (start < firstSeq)
start = firstSeq;
try {
// Loop until the user closes the connection
timestamper ts;
while (out.good())
{
// Remember when we started this grab...
uint64_t last = ts.get_timestamp();
// Fetch sample data now resets the observer while holding the sequence
// mutex to make sure that a new event will be recorded in the observer
// when it returns.
string content;
uint64_t end;
bool endOfBuffer = true;
if (current) {
content = fetchCurrentData(aFilter, NO_START);
} else {
// Check if we're falling too far behind. If we are, generate an
// MTConnectError and return.
if (start < getFirstSequence()) {
sLogger << LWARN << "Client fell too far behind, disconnecting";
throw ParameterError("OUT_OF_RANGE", "Client can't keep up with event stream, disconnecting");
} else {
// end and endOfBuffer are set during the fetch sample data while the
// mutex is held. This removed the race to check if we are at the end of
// the bufffer and setting the next start to the last sequence number
// sent.
content = fetchSampleData(aFilter, start, count, end,
endOfBuffer, &observer);
}
if (mLogStreamData)
log << content << endl;
}
ostringstream str;
// Make sure we're terminated with a <cr><nl>
content.append("\r\n");
out.setf(ios::dec, ios::basefield);
str << "--" << boundary << "\r\n"
"Content-type: text/xml\r\n"
"Content-length: " << content.length() << "\r\n\r\n"
<< content;
string chunk = str.str();
out.setf(ios::hex, ios::basefield);
out << chunk.length() << "\r\n";
out << chunk << "\r\n";
out.flush();
// Wait for up to frequency ms for something to arrive... Don't wait if
// we are not at the end of the buffer. Just put the next set after aInterval
// has elapsed. Check also if in the intervening time between the last fetch
// and now. If so, we just spin through and wait the next interval.
// Even if we are at the end of the buffer, or within range. If we are filtering,
//.........这里部分代码省略.........