本文整理汇总了C++中ofstream::width方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::width方法的具体用法?C++ ofstream::width怎么用?C++ ofstream::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::width方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dump
void ContractLineRec::dump(ofstream &of) const
{
of.width(2);
char fc = of.fill('0');
of << ContractLine
<< Date
<< PostingCode
<< Contract;
RecordFactory::DumpDouble(of, Amount);
RecordFactory::DumpDouble(of, Discount);
of << RefNum
<< SvcAddr
<< CoveragePeriod
<< RenewalPeriod
<< ConsecutiveMonthsLeft
<< ConsecutiveMonthsTotal;
RecordFactory::DumpDouble(of, Deviation);
of.width(3);
of << Location
<< '\n';
of.fill(fc);
}
示例2: captureNAClusterInfo
//============================================================================
// This method writes the information related to the NAClusterInfo class to a
// logfile called "NAClusterInfo.txt".
//============================================================================
void NAClusterInfo::captureNAClusterInfo(ofstream & naclfile)
{
CollIndex i, ci;
char filepath[OSIM_PATHMAX];
char filename[OSIM_FNAMEMAX];
// We don't capture data members that are computed during the compilation of
// a query. These include:
//
// * smpCount_;
// * tableToClusterMap_;
// * activeClusters_;
//
naclfile << "localCluster_: " << localCluster_ << endl
<< "localSMP_: " << localSMP_ << endl;
CollIndex *key_collindex;
maps *val_maps;
// Iterator for logging all the entries in clusterToCPUMap_ HashDictionary.
NAHashDictionaryIterator<CollIndex, maps> C2CPUIter (*clusterToCPUMap_, NULL, NULL);
naclfile << "clusterToCPUMap_: " << C2CPUIter.entries() << " :" << endl;
if (C2CPUIter.entries() > 0)
{
// Write the header line for the table.
naclfile << " ";
naclfile.width(10);
naclfile << "clusterNum" << " ";
naclfile << "cpuList" << endl;
for (i=0; i<C2CPUIter.entries(); i++)
{
C2CPUIter.getNext(key_collindex, val_maps);
naclfile << " ";
naclfile.width(10); naclfile << *key_collindex << " ";
naclfile << val_maps->list->entries() << " : ";
for (ci=0; ci<val_maps->list->entries(); ci++)
{
naclfile.width(3); naclfile << (*(val_maps->list))[ci] << " ";
}
naclfile << endl;
}
}
Int32 * nodeID = NULL;
NAString* nodeName = NULL;
NAHashDictionaryIterator<Int32, NAString> nodeNameAndIDIter (*nodeIdToNodeNameMap_);
naclfile << "nodeIdAndNodeNameMap: " << nodeNameAndIDIter.entries() << endl;
for(nodeNameAndIDIter.getNext(nodeID, nodeName); nodeID && nodeName; nodeNameAndIDIter.getNext(nodeID, nodeName))
{
naclfile << *nodeID << " " << nodeName->data() << endl;
}
// Now save the OS-specific information to the NAClusterInfo.txt file
captureOSInfo(naclfile);
}
示例3: InstImage
void InstImage(IMG img, void *v)
{
outfile << "-----------" << endl <<"Image name = " << IMG_Name(img) << endl << flush;
ADDRINT mappedStart = IMG_StartAddress(img);
ADDRINT mappedEnd = mappedStart + IMG_SizeMapped(img);
outfile << hex << showbase;
outfile << "mapped start " << mappedStart << " mapped end " << mappedEnd << endl;
ADDRINT virtStart = IMG_LowAddress(img);
ADDRINT virtEnd = IMG_HighAddress(img);
outfile << "low addr " << virtStart << " high address " << virtEnd << endl;
for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec))
{
ADDRINT secData = reinterpret_cast <ADDRINT > (SEC_Data(sec));
if (secData)
{
if ((secData < mappedStart) || (secData >= mappedEnd))
{
cout << "ERROR: Image " << IMG_Name(img) << " Section " << SEC_Name(sec) << " data wrong ptr: " << secData << endl;
exit(-1);
}
}
ADDRINT secAddr = SEC_Address(sec);
if (secAddr)
{
if ((secAddr < virtStart) || (secAddr >= virtEnd))
{
cout << "ERROR: Image " << IMG_Name(img) << "Section " << SEC_Name(sec) << " address wrong ptr: " << secAddr << endl;
exit(-1);
}
}
outfile << "Section \"";
outfile.width(30);
outfile << left << SEC_Name(sec) << "\"";
outfile << " \t data ptr ";
outfile.width(sizeof(ADDRINT)*2+4);
outfile << left << secData << " addr ptr " << secAddr << endl;
}
}
示例4: dumpNew
void TrailerRec::dumpNew(ofstream &of, int dumpCount, double dump_stmt_bal) const
{
of.width(2);
char fc = of.fill('0');
of << Trailer;
time_t tt = time(0);
struct tm *t = localtime(&tt);
char timebuf[14+1];
strftime(timebuf, sizeof(timebuf), "%m%d%y%I:%M %p", t);
of << timebuf;
of.fill(' ');
of.width(7);
of << dumpCount;
of.fill('0');
RecordFactory::DumpDouble(of, dump_stmt_bal, 10);
of << '\n';
of.fill(fc);
}
示例5: OpenStatisticsFile
/// \brief Opens the statistics file and sets the properties for the ofstream
///
/// \param file An uninitialized ofstream for the statistics files
void CMinimizerThread::OpenStatisticsFile(ofstream & file)
{
stringstream filename;
if(file.is_open())
file.close();
// Open the statistics file for writing:
filename.str("");
filename << mSaveDirectory << "/best_fit.txt";
file.open(filename.str().c_str());
file.width(15);
file.precision(8);
}
示例6: NextChar
char Scanner::NextChar()
{
char c;
sourceFile.get(c);
if (c == '\n')
{
listFile.width(6);
listFile << ++lineNumber << " " << lineBuffer << endl;
lineBuffer = "";
}
else
lineBuffer += c;
return c;
}
示例7:
/** writes the genotype of the individual to the stream (for multiple instances of the same trait)*/
void FileHandler::FHwriteIndividual2Stream(ofstream& FILE, Individual* ind, const int& ploidy, const int& position){
int nb_locus;
unsigned char** seq;
for(int t=0; t<_nb_trait; ++t){
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<<" ";
}
}
}
示例8: image_pixel
static void image_pixel( void *userdata, ofstream& fp, unsigned char *rgb)
{
unsigned char transp[3] = {255,0,255};
int grey;
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2])
grey = 255;
else
grey = (int) ((0.0 + *rgb + *(rgb+1) + *(rgb+2)) / 3 + 0.5);
fp.width(2);
fp << grey;
if ( ++char_cnt >= 40) {
char_cnt = 0;
fp << endl;
}
}
示例9: isis2ascii
void isis2ascii(Buffer &in) {
for(int i = 0; i < in.size(); i++) {
fout.width(13); // Width must be set everytime
if(IsSpecial(in[i])) {
if(IsNullPixel(in[i])) fout << "NULL";
if(IsHrsPixel(in[i])) fout << "HRS";
if(IsHisPixel(in[i])) fout << "HIS";
if(IsLrsPixel(in[i])) fout << "LRS";
if(IsLisPixel(in[i])) fout << "LIS";
}
else {
fout << in[i];
}
}
fout << endl;
}
示例10: write_to_stream
/**
* Function to write Undergraduate student's data to an output file
* stream that has been opened
*/
void Undergraduate::write_to_stream (ofstream & outputfile) {
// Left align the data
outputfile.setf(ios::left);
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << "Undergraduate";
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << Student::get_lastname();
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << get_firstname();
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << get_ssn();
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << get_phone();
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << get_age();
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << get_major();
outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS);
outputfile << get_minor() << endl;
//outputfile << endl;
}
示例11: _subject
std::vector<token_lexeme_pair> lexically_analyze(ifstream &code_file, ofstream &lex_file, ofstream &symbol_file)
{
if ( ! code_file.is_open())
throw "File not found";
std::unordered_set<string> symbols;
std::vector<token_lexeme_pair> token_lexemes;
int line_number = 1;
DFA dfaz[DFA_COUNT];
initialize(dfaz[0], dfaz[1], dfaz[2], dfaz[3], dfaz[4], dfaz[5], dfaz[6], dfaz[7], dfaz[8], dfaz[9]);
int curr_dfa = 0;
int consecutive_break_count = 0; // To check for symbols not in the language.
std::string _subject((std::istreambuf_iterator<char>(code_file)), (std::istreambuf_iterator<char>()));
for (unsigned int _index = 0; _index < _subject.size(); _index++) {
if (_subject[_index] == '\n')
line_number++;
if (consecutive_break_count == DFA_COUNT || _subject[_index] == ' ' || _subject[_index] == '\n' || _subject[_index] == '\t' || _subject[_index] == '\0') {
consecutive_break_count = 0;
continue;
}
int i = _index;
string str;
int last_state = 0;
for (unsigned int j = i; ; j++) {
// DFA breaks.
int result = dfaz[curr_dfa].simulate_symbol(_subject[j]);
if (result == dfaz[curr_dfa].get_reserved_state()) {
if (last_state) { // Keep the 'str' string because a token has been found.
consecutive_break_count = 0;
_index = j - 1; // Continue where this DFA broke.
}
else { // Return to original position.
str.clear();
_index = i - 1;
consecutive_break_count++;
}
break;
}
// DFA enters into a neutral state.
if (result == 0) {
if (_subject[j] == '\n')
line_number++;
str.push_back(_subject[j]);
last_state = 0;
}
// DFA enters into an accept state.
if (result == 1) {
_index = j;
str.push_back(_subject[j]);
last_state = 1;
}
}
// Token found.
if (str.size() > 0) {
if (dfaz[curr_dfa].getName() == "identifier" && check_keyword(str)) {
token_lexemes.push_back(token_lexeme_pair("keyword", str, line_number));
}
else {
token_lexemes.push_back(token_lexeme_pair(dfaz[curr_dfa].getName(), str, line_number));
}
if (dfaz[curr_dfa].getName() == "identifier" && !check_keyword(str)) {
symbols.insert(str);
}
}
// Change DFA.
curr_dfa++;
if (curr_dfa == DFA_COUNT)
curr_dfa = 0;
}
for (const auto& elem : symbols) {
symbol_file << elem <<endl;
}
lex_file << setw(15);
for (std::vector<token_lexeme_pair>::iterator it = token_lexemes.begin(); it != token_lexemes.end(); it++) {
lex_file.width(30);
//.........这里部分代码省略.........
示例12: report_blast
/// output Blast-like alignments (code modified from SSW-library)
void report_blast (ofstream &fileout,
s_align* a,
char* read_name,
char* read_seq,
char* read_qual,
char* ref_name,
char* ref_seq,
double evalue,
uint32_t readlen,
uint32_t bitscore,
bool strand, // 1: forward aligned ; 0: reverse complement aligned
double id,
double coverage,
uint32_t mismatches,
uint32_t gaps
)
{
char to_char[5] = {'A','C','G','T','N'};
// Blast-like pairwise alignment (only for aligned reads)
if ( blast_outfmt == 0 )
{
fileout << "Sequence ID: ";
char* tmp = ref_name;
while (*tmp != '\n') fileout << *tmp++;
fileout << endl;
fileout << "Query ID: ";
tmp = read_name;
while (*tmp != '\n') fileout << *tmp++;
fileout << endl;
fileout << "Score: " << a->score1 << " bits (" << bitscore << ")\t";
fileout.precision(3);
fileout << "Expect: " << evalue << "\t";
if (strand) fileout << "strand: +\n\n";
else fileout << "strand: -\n\n";
if (a->cigar)
{
uint32_t i, c = 0, left = 0, e = 0, qb = a->ref_begin1, pb = a->read_begin1; //mine
while (e < a->cigarLen || left > 0)
{
int32_t count = 0;
int32_t q = qb;
int32_t p = pb;
fileout << "Target: ";
fileout.width(8);
fileout << q+1 << " ";
for (c = e; c < a->cigarLen; ++c)
{
uint32_t letter = 0xf&*(a->cigar + c);
uint32_t length = (0xfffffff0&*(a->cigar + c))>>4;
uint32_t l = (count == 0 && left > 0) ? left: length;
for (i = 0; i < l; ++i)
{
if (letter == 1) fileout << "-";
else
{
fileout << to_char[(int)*(ref_seq + q)];
++q;
}
++ count;
if (count == 60) goto step2;
}
}
step2:
fileout << " " << q << "\n";
fileout.width(20);
fileout << " ";
q = qb;
count = 0;
for (c = e; c < a->cigarLen; ++c)
{
uint32_t letter = 0xf&*(a->cigar + c);
uint32_t length = (0xfffffff0&*(a->cigar + c))>>4;
uint32_t l = (count == 0 && left > 0) ? left: length;
for (i = 0; i < l; ++i)
{
if (letter == 0)
{
if ((char)to_char[(int)*(ref_seq + q)] == (char)to_char[(int)*(read_seq + p)]) fileout << "|";
else fileout << "*";
++q;
++p;
} else
{
fileout << " ";
if (letter == 1) ++p;
else ++q;
}
++ count;
if (count == 60)
{
qb = q;
goto step3;
}
}
}
step3:
//.........这里部分代码省略.........
示例13: isspace
void MapAndDump(char* pcRow)
{
std::map<int, string> msg;
std::map<int, string>::iterator it;
string sLocal(pcRow);
string sDummy;
size_t pos;
if ((pos = sLocal.find(cSep)) == string::npos)
{
return;
}
sLocal = sLocal.substr(sLocal.substr(0, pos).find_last_of(' ') + 1);
sLocal = sLocal.substr(strcspn(sLocal.c_str(), "0123456789"));
string sFixString = sLocal;
if ((pos = sFixString.find_last_of(cSep)) != string::npos)
{
sFixString = sFixString.substr(0, pos + 1);
}
string sTag;
while((sLocal.length() > 0) && (isdigit(sLocal[0]) || isspace(sLocal[0])))
{
pos = sLocal.find(cSep);
if (pos == string::npos)
{
sTag = sLocal;
sLocal = "";
}
else
{
sTag = sLocal.substr(0, pos);
sLocal = sLocal.substr(pos + 1);
}
// cerr << "New tag: " << sTag <<endl;
pos = sTag.find("=");
msg[atoi(sTag.substr(0, pos).c_str())] = sTag.substr(pos + 1);
}
if (lOptValue & PRGOPT_MSGLIST)
{
pos = sFixTypesList.find((char)(*msg[35].c_str()));
if (pos == string::npos)
{
return;
}
}
if (!(lOptValue & PRGOPT_SEPARATOR) &&
((it = msg.find(35)) == msg.end()))
{
return;
}
if ((lOptValue & PRGOPT_FILTER) && !isFilterTrue(msg, iFilterOnTag, sFilterOnTagValue))
return;
if (lOptValue & PRGOPT_BAREDUMP)
{
os << sFixString << endl;
return;
}
if (lOptValue & PRGOPT_PRINTHDR)
{
os << "\n----------------*" << endl;
os << "Message Type: " <<
mFixMsgType[(char)(*msg[35].c_str())] << endl;
os << "Sent from : " << msg[49] << endl;
os << "Sent to : " << msg[56] << endl;
os << endl;
}
sDummy = " ";
string sSep = "";
stringstream ssCsvSep;
ssCsvSep << csvSep;
for(it = msg.begin(); it != msg.end(); it++)
{
int iTag = (*it).first;
if (!(lOptValue & PRGOPT_TAGLIST) ||
(lOptValue & PRGOPT_TAGLIST) && (isInList(iTag)))
{
if (!(lOptValue & PRGOPT_COMMASEP))
{
os.width(iTagWidth);
os << (*it).first;
os << " => ";
if (iDescWidth)
{
os << (*it).second.substr(0, iDescWidth);
if ((*it).second.substr(0, iDescWidth).length() < iDescWidth)
{
os << sDummy.substr(0, iDescWidth -
(*it).second.substr(0, iDescWidth).length());
}
os << endl;
//.........这里部分代码省略.........
示例14: writeModel
void GeometryExportFile::writeModel( Object *o, ofstream &out )
{
out <<
"{ 'MODL'\n"
" { 'SRC' \"Innovation 3D exported by WF geometry exporter V0.11\""
" }\n"
" { 'TRGT' \"World Foundy Game Engine (www.worldfoundry.org)\"\n"
" }\n" << endl;
out <<
" { 'NAME' \"" << o->getName() << "\"\n"
" }\n";
out.setf(std::ios::showpoint);
//Vector4 pos;
float texturex=0;
float texturey=0;
float color=0;
//pos = o->getPosition();
int oldWidth = out.width(8);
char oldFill = out.fill('0');
// kts i3d is a left handed coordinate system with positive y up, WF is left handed with positive z up
// so I rotate -90 degrees around x putting y up (swap y&z, negate the new y)
VertexList *vlist = o->getVerts();
int size = (int)vlist->size();
Vector4 vertpos;
Vector4 uv;
for(int i=0; i<size; i++)
{
vertpos = (*vlist)[i]->getPosition();
VertexAndUV vuv;
vuv.position = vertpos;
}
CreateVertUVList(o);
WriteVertexList(out);
out << " { 'MATL' //flags: [FLAT_SHADED=0, GOURAUD_SHADED=1] [SOLID_COLOR=0, TEXTURE_MAPPED=2] [SINGLE_SIDED=0, TWO_SIDED=8]" << endl;
//save materials here.
ObjectDB *odb = I3D::getDB();
TextureMaterial *m;
for(int materialIndex=0; materialIndex<odb->numMaterials(); materialIndex++)
{
m = odb->getMaterial(materialIndex);
_MaterialOnDisk mod;
mod._materialFlags = 0;
if(m->enable_texture)
mod._materialFlags |= TEXTURE_MAPPED;
for(int temp=0;temp<MATERIAL_NAME_LEN;temp++)
mod.textureName[temp] = 0;
if(m->texture)
strncpy(mod.textureName, m->texture->getFilename()->ascii(), MATERIAL_NAME_LEN);
mod.textureName[MATERIAL_NAME_LEN-1] = 0; // make sure it is 0 terminated
mod._color = ((((unsigned int)m->cDiffuse.r)<<16) |
(((unsigned int)m->cDiffuse.g)<<8) |
((unsigned int)m->cDiffuse.b));
out << " //Material " << materialIndex << ": flags: " << mod._materialFlags << ", color: " << hex << mod._color << dec << ", texturename: \"" << mod.textureName << "\"" << endl;
out << " ";
for(int index=0;index<sizeof(_MaterialOnDisk);index++)
{
out << (unsigned int)(((unsigned char*)&mod)[index]) << "y ";
}
out << " // #" << materialIndex << endl;
}
out << " }" << endl;
// faces
size = (int)o->numFaces();
out << " { 'FACE' // count = " << size << endl;
for(int faceIndex=0; faceIndex<size; faceIndex++)
{
Face* face = o->getFace(faceIndex);
vector<int> *vlist = face->getVerts();
vector<int> *uvlist = face->getUVs();
assert(vlist->size() >= 3); // must be at least a triangle
// output list of triangles for this face
//.........这里部分代码省略.........