本文整理汇总了C++中std::fstream::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::clear方法的具体用法?C++ fstream::clear怎么用?C++ fstream::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::fstream
的用法示例。
在下文中一共展示了fstream::clear方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strip_file
/******************************************************************************************************
void strip_file(std::ifstream& inStream, std::string fileName)
Description: Opens a input file and strips symbols and outputs to temp file.
Parameters: std::ifstream& inStream, std::string fileName
Pre-Conditions: Input file must be opened.
Post-Conditions: Input file will be stripped of symnbols and output to temp file.
******************************************************************************************************/
void strip_file(std::ifstream& inStream, std::fstream& tempStream)
{
std::vector<char> lines;//create a vector to hold characters.
while (inStream)//iterate through each line in file.
{
char ch;
int count = 0;
ch = inStream.get();//Get character from line.
while (ch != EOF)//While not end of line.
{
if (ch != ',' && ch != '[' && ch != ']')//Do not add these symbols.
{
lines.push_back(ch);//Push character to vector.
count++;//inc count, used to loop through vector.
}
ch = inStream.get();//get next char in line.
}
for (int i = 0; i < count; i++)
{
//std::cout << lines[i]; //Outputs each line in file to console.
tempStream << lines[i];//Outputs to temp.txt file
}
lines.clear();//Clears the vector of all values.
}
inStream.clear();//clears the end of file flag (eof).
inStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream.
tempStream.clear();//clears the end of file flag (eof).
tempStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream.
}//end strip_file
示例2:
static void
clear(std::fstream& f)
{
f.clear();
errno = 0;
return;
}
示例3: runtime_error
void filesystem::supercluster::save(std::fstream& s, uint32_t index)
{
uint64_t offset = SUPERCLUSTER_SIZE * index;
char buffer[CLUSTER_SIZE];
for(unsigned i = 0; i < CLUSTERS_PER_SUPER; i++)
serialization::u32b(buffer + 4 * i, clusters[i]);
s.clear();
s.seekp(offset, std::ios_base::beg);
s.write(buffer, CLUSTER_SIZE);
if(!s)
throw std::runtime_error("Can't write cluster table");
}
示例4: getImageCount
static int getImageCount(std::fstream& file_list)
{
int sample = 0;
std::string line;
while (std::getline(file_list, line))
++sample;
if (file_list.eof())
file_list.clear(); //otherwise we can't do any further I/O
else if (file_list.bad()) {
throw std::runtime_error("Error occured while reading files_list.txt");
}
return sample;
}
示例5: seek
virtual bool seek(int32 offset, int whence = SEEK_SET) {
_fileStream->clear();
switch (whence) {
case SEEK_SET:
_fileStream->seekg(offset, std::ios_base::beg);
break;
case SEEK_CUR:
_fileStream->seekg(offset, std::ios_base::cur);
break;
case SEEK_END:
_fileStream->seekg(offset, std::ios_base::end);
break;
}
}
示例6: leerLinea
void Agente::leerLinea(std::fstream& archivo, std::string& linea) {
linea.clear();
char buffer[T_BUFFER];
bool seguirLeyendo = true;
do {
archivo.getline(buffer, T_BUFFER, '\n');
linea.append(buffer, archivo.gcount());
seguirLeyendo = (archivo.gcount() == T_BUFFER);
if (archivo.bad())
archivo.clear();
} while (seguirLeyendo);
}
示例7: FileLoader
void CFileManager::FileLoader(std::fstream& i_stream,std::string i_filepath)
{
i_stream.clear();
//i_stream.open(i_filepath.c_str());
i_stream.open("TestData.txt");
if(i_stream.is_open())
{
//i_stream << "opened this file";
i_stream >> token;
if(token == "gobblin")
{
//characters.push_back( CHARACTER() );
//LoadGoblin( file, characters.back() );
}
i_stream.close();
}
示例8: checkformodifications
void resultsfile::checkformodifications(std::fstream& file)
{
assert(file.good());
trace << "DEBUG (resultsfile): checking file for modifications." << std::endl;
// check for user modifications
sha curdigest;
file.seekg(0);
curdigest.process(file);
// reset file
file.clear();
if (curdigest == filedigest)
file.seekp(fileptr);
else
{
cerr << "NOTICE: file modifications found - appending." << std::endl;
// set current write position to end-of-file
file.seekp(0, std::ios_base::end);
fileptr = file.tellp();
}
}
示例9: search_forward
std::streampos search_forward ( std::fstream & _bs, const std::string & sample )
{
size_t match ( 0 );
cSaveIStreamPosition ip ( &_bs );
streampos result ( static_cast<streampos>( -1 ) );
cSaveStreamExceptions se ( &_bs, std::ios_base::goodbit );
for( int ch( EOF ); match < sample.length(); match++ )
{
ch = _bs.get();
if( ch == EOF )
break;
else if( ch != sample[match] )
match = 0;
}
if( match == sample.length() )
result = _bs.tellg() - static_cast<streampos>( match );
_bs.clear();
return result;
}
示例10: refreshFstream
void refreshFstream(std::fstream& fs)
{
fs.clear();
fs.seekg(0,fs.beg);
}