本文整理汇总了C++中ofstream::setf方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::setf方法的具体用法?C++ ofstream::setf怎么用?C++ ofstream::setf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::setf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveOBJ
bool SaveOBJ(ofstream& fout, const double* const& points, const int* const& triangles, const unsigned int& nPoints,
const unsigned int& nTriangles, const Material& material, IVHACD::IUserLogger& logger, int convexPart, int vertexOffset)
{
if (fout.is_open()) {
fout.setf(std::ios::fixed, std::ios::floatfield);
fout.setf(std::ios::showpoint);
fout.precision(6);
size_t nV = nPoints * 3;
size_t nT = nTriangles * 3;
fout << "o convex_" << convexPart << std::endl;
if (nV > 0) {
for (size_t v = 0; v < nV; v += 3) {
fout << "v " << points[v + 0] << " " << points[v + 1] << " " << points[v + 2] << std::endl;
}
}
if (nT > 0) {
for (size_t f = 0; f < nT; f += 3) {
fout << "f "
<< triangles[f + 0]+vertexOffset << " "
<< triangles[f + 1]+vertexOffset << " "
<< triangles[f + 2]+vertexOffset << " " << std::endl;
}
}
return true;
}
else {
logger.Log("Can't open file\n");
return false;
}
}
示例2: main
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
int i,j,t;
double tmp;
cin>>t;
while(t > 0)
{
cin>>n>>tmp;
m = tmp * 100.00000000 + 0.5;
for( i = 1 ; i <= n ; ++ i)
{
cin>>w[ i ]>>v[ i ];
v[ i ] = v[ i ] * 100 + 0.5;
}
for( i = 1 ; i <= n ; ++ i)
for( j = int( m ) ;j >= int(v[ i ]) ; -- j)
if( f[ j ] < f[ j - int(v[ i ]) ] + w[ i ] )
f[ j ] = f[ j - int(v[ i ]) ] + w[ i ];
cout<<f[ int(m) ]<<"\n";
for( i = int( m ) ; i >= 0 ; -- i ) f[ i ] = 0;
--t;
}
return 0;
}
示例3: setPrintPrecision
void setPrintPrecision(int print_precision, ofstream& out) {
cout.setf(std::ios::scientific);
cout.precision(print_precision);
out.setf(std::ios::fixed);
out.precision(print_precision);
out.setf(ios::showpoint);
}
示例4: percentDiff
void percentDiff(double valA, double valB, ofstream& foutA)
{
double result;
result = ( fabs(valA - valB) / ( (valA + valB) / 2) ) * 100;
foutA.setf(ios::fixed);
foutA.setf(ios::showpoint);
foutA.precision(2);
foutA << setw(15) << result << " %" << endl;
foutA.precision(6);
} // end of percent diff
示例5: work
/*
Example:
After applying work():
1: MPI_Bcast= (void buffer= 1198516368, int count= 80, MPI_Datatype datatype= 1247288704, int root= 0,
MPI_Comm comm= 6604320, )S=[ 1367981215084679 ] E=[ 1367981215086238 ] D=[ 1559 ]
*/
void work()
{
string s;
int count = 0;
double startTime, endTime, durTime;
getline(fin ,s);
while (fin)
{
count++;
fout << count << ": ";
char *str = (char *) s.c_str();
char *p = strtok(str, " ");
startTime = atof(p);
p = strtok(NULL, " ");
string funcName(p);
fout << funcName << "= ";
p = strtok(NULL, " ");
string funcArgs(p);
fout << funcArgs ;
fout.setf(ios::fixed);
fout << "S=[ " << startTime << " ] ";
p = strtok(NULL, " ");
string ret_value(p);
fout.setf(ios::fixed);
fout << "R=[ " << ret_value << " ] ";
p = strtok(NULL, " ");
durTime = atof(p);
endTime = startTime + durTime;
fout << "E=[ " << endTime << " ] ";
fout << "D=[ " << durTime << " ] ";
fout << std::endl;
getline(fin ,s);
}
}
示例6: Fini
// This function is called when the application exits
VOID Fini(INT32 code, VOID *v)
{
if (icount1 != icount2 || icount1 != icount3 || icount1 != icount4 || icount1 != icount5
|| thenCount!=0)
{
// Write to a file since cout and cerr maybe closed by the application
OutFile.open(KnobOutputFile.Value().c_str());
OutFile.setf(ios::showbase);
if (thenCount!=0)
{
OutFile << "****ERROR thenCount was expected to be 0 not: " << thenCount << endl;
}
else
{
OutFile << "Count1 " << icount1 << endl;
OutFile << "Count2 " << icount2 << endl;
OutFile << "Count3 " << icount3 << endl;
OutFile << "Count4 " << icount3 << endl;
OutFile << "Count5 " << icount3 << endl;
OutFile << "***ERROR - mismatch in icounts " << endl;
}
OutFile.close();
exit (1);
}
}
示例7: TryOpen
static void TryOpen(ofstream& f, const char* name){
f.open(name);
f.setf(ios::showbase);
if (f.fail()){
ErrorExit("cannot open output file: " << name, MetasimError_FileOp);
}
}
示例8: Fini
// This function is called when the application exits
VOID Fini(INT32 code, VOID *v)
{
// Write to a file since cout and cerr maybe closed by the application
OutFile.setf(ios::showbase);
OutFile << "Count " << icount << endl;
OutFile.close();
}
示例9: main
int main(int argc, CHAR *argv[])
{
char * s = getenv("LD_ASSUME_KERNEL");
if (s == 0)
printf("LD_ASSUME_KERNEL not set\n");
else if (strcmp(s,"2.4.1") != 0)
printf("LD_ASSUME_KERNEL is wrong: %s\n",s);
PIN_InitSymbols();
if( PIN_Init(argc,argv) )
{
return Usage();
}
TraceFile.open(KnobOutputFile.Value().c_str());
TraceFile << hex;
TraceFile.setf(ios::showbase);
IMG_AddInstrumentFunction(ImageLoad, 0);
PIN_StartProgramProbed();
return 0;
}
示例10: PutTable
/** Put a table of node values. This table is as compact
as possible while still maintaining readability
*/
void NodeList::PutTable( ofstream& s )
{
s.precision(4);
s.setf( ios::right, ios::adjustfield );
s << GNU_COMMENT << " NodeList\n"
<< GNU_COMMENT << "=========\n";
s << GNU_COMMENT << ' '
<< setw( 6) << "Id(1) "
<< setw(13) << "x(2) "
<< setw(13) << "fluxS(3) "
<< setw(13) << "fluxD(4) "
<< setw(13) << "fluxE(5) "
<< setw(13) << "left id(6) "
<< setw(13) << "right id(6) "
<< '\n';
SetLineStyle( '-' );
PutLine( s, 106 );
for( int i=0; i<n; i++ ){
node[i].PutTable( s );
}
s.flush();
}
示例11: main
int main(int argc, char* argv[])
{
if ( PIN_Init(argc, argv) )
return Usage();
PIN_InitSymbols();
// Initialize trace
trace.open(KnobOutputFile.Value().c_str());
trace << hex;
trace.setf(ios::showbase);
// Intialize stack tracing code
IMG_AddInstrumentFunction(I_ImageLoad, 0);
TRACE_AddInstrumentFunction(I_Trace, 0);
// Initialize memory tracing code
INS_AddInstrumentFunction(Instruction, 0);
IMG_AddInstrumentFunction(Image, 0);
// Initialize cleanup code
PIN_AddFiniFunction(Fini, 0);
PIN_StartProgram();
assert(false && "Control should never reach here!");
return 0;
}
示例12: outputNet
//Output values for neural network
void outputNet(neuNet network, ofstream &output) {
output.setf(ios::fixed,ios::floatfield);
output.precision(3);
output << network.input.size() << " "; //output number of inputs
output << network.hidden.size() << " "; //output number of hidden nodes
output << network.output.size() << endl; //output number of outputs
//output weights of input-hidden node edges
for (int i = 0; i < network.hid_in.size(); ++i) {
for (int j = 0; j < network.hid_in[i].size(); ++j) {
//if-else to prevent placing space at end of line
if (j != network.hid_in[i].size()-1)
output << "input hidden: " << network.hid_in[i][j] << " ";
else
output << "input hidden: " << network.hid_in[i][j];
}
output << endl;
}
//output weights of hidden node-output edges
for (int i = 0; i < network.out_hid.size(); ++i) {
for (int j = 0; j < network.out_hid[i].size(); ++j) {
//if-else to prevent placing space at end of line
if (j != network.out_hid[i].size()-1)
output << "output weight: " << network.out_hid[i][j] << " ";
else
output << "output weight: " << network.out_hid[i][j];
}
output << endl;
}
}
示例13: write
void write(ofstream& out, Car c[], int size)
{
for(int i=0; i < size; i++)
{
Car CAR = c[i];
out.setf(ios::fixed);
out.setf(ios::showpoint);
out.precision(2);
out << CAR.make << " " << CAR.model << " " << CAR.year << " "
<< CAR.price << " " << CAR.miles << " " << CAR.getValue() << endl;
}
return;
}
示例14: init_log
void init_log(const VolModel model, const RunMode runmode, ofstream& log_stream)
{
string logfile = "./log_" + get_model_name(model) + "_" + get_run_mode(runmode);
cout<<"log file is: "<<logfile<<endl;
log_stream.open(logfile.c_str());
log_stream.setf(ios::fixed);
log_stream<<setprecision(10);
}
示例15: processing
void processing(ifstream& inFile, ofstream& outFile)
{ //variable declarations
char letter;
double number, avg, sum(0);
//sets precision and decimal place
outFile.setf(ios::fixed);
outFile.setf(ios::showpoint);
outFile.precision(2);
outFile << "********************************************" << endl
<< "Student Name: ";
//outputs name to result.txt
while(letter != '\n')
{
inFile.get(letter);
outFile.put(letter);
}
outFile << "Test Scores: ";
//outputs scores and finds their sum
inFile >> number;
while(! inFile.eof( ))
{
sum += number;
outFile << number << setw(8);
inFile >> number;
}
//calculates average
avg = sum / 5.0;
outFile << endl << "Average Score: " << avg << endl
<< "********************************************" << endl;
}