本文整理汇总了C++中ofstream::bad方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::bad方法的具体用法?C++ ofstream::bad怎么用?C++ ofstream::bad使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::bad方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
int LgScriptWriter::write(State&, const char* p, size_t sz)
{
if (sz != 0)
{
outfile.write(p, sz);
if (outfile.bad())
return -1;
}
return 0;
}
示例2: copyToFile
int HTTPRequest::copyToFile(ofstream& ofs)
{
size_t contentLength = atoi(getHTTPHeader("Content-Length").c_str());
if (ofs.good())
{
ofs.write(m_requestBody.c_str(), contentLength);
}
if (ofs.bad())
return -1;
return 0;
}
示例3: exportToDbTables
bool TissueState::exportToDbTables(const int ImageHeight, ofstream& framesFile, ofstream &verticesFile, ofstream &cellsFile, ofstream &ignoredCellsFile, ofstream &undirectedBondsFile, ofstream &directedBondsFile, unsigned long &lastVid, unsigned long &lastDbid, unsigned long &lastUbid) const {
if(contains(Cell::VoidCellId)) {
std::cout << "Found void cell id " << Cell::VoidCellId << " in frame " << _frameNumber << "!" << std::endl;
return false;
}
// add data to frames table
framesFile << _frameNumber << LogFile::DataSeparator << _time << '\n';
if(framesFile.bad()) {
std::cout << "Error writing frame data!" << std::endl;
return false;
}
// add data to vertex table and generate map: vertex pointer -> vid
std::map<Vertex*,unsigned long> vertexPointerToVid;
for(int i=0; i<numberOfVertices(); ++i) {
Vertex *v = vertex(i);
++lastVid;
vertexPointerToVid[v] = lastVid;
// write data:
verticesFile << _frameNumber << LogFile::DataSeparator << lastVid << LogFile::DataSeparator << v->r.x() << LogFile::DataSeparator << ImageHeight-1-v->r.y() << '\n';
if(verticesFile.bad()) {
std::cout << "Error writing vertex data!" << std::endl;
return false;
}
}
// add data to cell table and generate map for bond sorting within cells
std::map<DirectedBond*,DirectedBond*> leftBondSeenFromCellMap;
// void cell
cellsFile << _frameNumber << LogFile::DataSeparator << Cell::VoidCellId
<< LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0
<< LogFile::DataSeparator << -1 << LogFile::DataSeparator << -1 << LogFile::DataSeparator << 0
<< LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0
<< LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0
<< LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0
<< LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0
<< '\n';
// other cells
for(TissueState::CellConstIterator it=beginCellIterator(); it!=endCellIterator(); ++it) {
Cell *c = cell(it);
for(unsigned int j=0; j<c->bonds.size(); ++j) {
leftBondSeenFromCellMap[c->bonds[j]] = c->bonds[(j+1)%c->bonds.size()];
}
// write data; revert signs of nematic xy components such that the values in the .dat files corresponds to a coordinate system with the y axis pointing upwards
cellsFile << _frameNumber << LogFile::DataSeparator << c->id
<< LogFile::DataSeparator << (int)c->duringTransitionBefore << LogFile::DataSeparator << (int)c->duringTransitionAfter << LogFile::DataSeparator << c->daughter
<< LogFile::DataSeparator << c->r.x() << LogFile::DataSeparator << ImageHeight-1-c->r.y() << LogFile::DataSeparator << c->area
<< LogFile::DataSeparator << c->elongation.c1() << LogFile::DataSeparator << -c->elongation.c2()
<< LogFile::DataSeparator << c->polarityR.c1() << LogFile::DataSeparator << -c->polarityR.c2() << LogFile::DataSeparator << c->intIntensityR
<< LogFile::DataSeparator << c->polarityG.c1() << LogFile::DataSeparator << -c->polarityG.c2() << LogFile::DataSeparator << c->intIntensityG
<< LogFile::DataSeparator << c->polarityB.c1() << LogFile::DataSeparator << -c->polarityB.c2() << LogFile::DataSeparator << c->intIntensityB
<< '\n';
if(cellsFile.bad()) {
std::cout << "Error writing cell data!" << std::endl;
return false;
}
}
// ignored cells
for(set<CellIndex>::const_iterator it=_ignoredCells.begin(); it!=_ignoredCells.end(); ++it) {
// write data:
ignoredCellsFile << _frameNumber << LogFile::DataSeparator << *it << '\n';
if(ignoredCellsFile.bad()) {
std::cout << "Error writing data for ignored cells!" << std::endl;
return false;
}
}
// add data to undirected bonds table and generate map: bond pointer -> dbid
std::map<DirectedBond*,unsigned long> directedBondPointerToDbid;
std::map<DirectedBond*,unsigned long> directedBondPointerToUbid;
std::map<DirectedBond*,unsigned long> newConjBondDbids;
std::map<DirectedBond*,DirectedBond*> newConjBondLeftOfConjBondAsSeenFromVoidCell;
for(TissueState::BondConstIterator it=beginBondIterator(); it!=endBondIterator(); ++it) {
DirectedBond *b = bond(it);
++lastDbid;
directedBondPointerToDbid[b] = lastDbid;
if(!b->conjBond) {
++lastDbid;
newConjBondDbids[b] = lastDbid;
// conj bond of bond left of conj bond seen from void cell
Vertex *v = b->rightVertex;
unsigned int i;
for(i=0; i<v->bonds.size(); ++i) {
if(v->bonds[i]==b) break;
}
if(i==v->bonds.size()) {
std::cout << "TissueState::exportToDbTables: bond not found within rightVertex!" << std::endl;
throw std::exception();
}
DirectedBond *oneBondCwAtVertex = v->bonds[ (i+v->bonds.size()-1)%v->bonds.size() ];
Cell *c = oneBondCwAtVertex->cell;
for(i=0; i<c->bonds.size(); ++i) {
if(c->bonds[i]==oneBondCwAtVertex) break;
}
if(i==c->bonds.size()) {
//.........这里部分代码省略.........
示例4: patchFile
int KiCadSCH::patchFile(ofstream &oFile)
{
string iline, oline, last_oline;
modiFile_t currentpatch;
int line_n;
unsigned i;
unsigned olineNbr = 0;
iSCHfile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
oFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try{
last_oline = "";
for(line_n=0; true; line_n++){
getline(iSCHfile, iline);
oline = iline;
currentpatch.add = false;
currentpatch.del = false;
currentpatch.line = "";
currentpatch.lineNbr = 0;
for(i=0;i<patchvec.size();i++){
if(line_n == patchvec[i].lineNbr){
currentpatch = patchvec[i];
patchvec[i].prevline = last_oline;
if(currentpatch.add){
oFile << currentpatch.line << endl;
olineNbr++;
patchvec[i].olineNbr = olineNbr;
}
}
}
if(!currentpatch.del){
oFile << oline << endl;
last_oline = oline;
olineNbr++;
if(patchvec.size()>i){ // if patchvec is empty
patchvec[i].olineNbr = olineNbr;
}
}else{
if(patchvec.size()<i) patchvec[i].deletedline = oline;
}
}
}
catch(std::fstream::failure e){
if(iSCHfile.bad()) return -1;
if(oFile.bad()) return -2;
if(iSCHfile.fail()) return -1;
if(oFile.fail()) return -2;
if(iSCHfile.eof()){
iSCHfile.clear();
iSCHfile.seekg(0, ios::beg);
return 0;
}
if(oFile.eof()) {
oFile.clear();
return -2;
}
return -255;
}
return 0;
}