本文整理汇总了C++中ofstream::eof方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::eof方法的具体用法?C++ ofstream::eof怎么用?C++ ofstream::eof使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::eof方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jumpToLine
//jump to line n in functions
bool MapBuilder::jumpToLine(int n, ifstream &lookFile, ofstream &putFile){
bool newLine = false;
lookFile.seekg(ios_base::beg); //set cursor to the beginning
int counter = 0;
while((n < counter) && (!file.eof())){ //search for n new lines
if(findsNLChar(lookFile)){ //if you find a new line
counter++; //count that
}
}
if(!lookFile.eof()){ //if we got to the end before making n lines
return false; //we never made it
}
putFile.seekp(lookFile.tellg()); //put the putting pointer to where looking pointer is
return true; //successfully got to line n
}
示例2:
bool
csv_fwrite (ofstream &fp, string src)
{
if (fp == NULL || fp.eof())
return false;
fp << '"';
for (unsigned int i = 0; i < src.length(); i++) {
if (src[i] == '"') {
fp << '"';
}
fp << src[i];
}
fp << '"';
return true;
}
示例3: 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;
}