本文整理汇总了C++中std::istream::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::clear方法的具体用法?C++ istream::clear怎么用?C++ istream::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFace
void FileLoader::readFace(std::istream& is, Mesh& object)
{
GLuint in;
while(is.good())
{
// read index of geometry vertex
while(is >> in) object.v_f.push_back(in-1);
if(is.fail())
{
is.clear();
char sign;
is >> sign;
if(sign == '/')
{
// read index of texture vertex
if(is >> in) object.vt_f.push_back(in-1);
if(is.fail())
{
is.clear();
char sign;
is >> sign;
if(sign == '/')
{
// read index of normal vertex
if(is >> in) object.vn_f.push_back(in-1);
}
}
}
}
示例2: ReadValueStr
std::string ReadValueStr(std::string prompt /*= std::string()*/, std::istream& in /*= std::cin*/, std::ostream* out /*= &std::cout*/)
{
if (out)
(*out) << prompt;
std::string input;
bool success = false;
while (!success)
{
std::getline(in, input);
if (in.fail())
{
if (in.eof())
{
in.clear();
throw EOFCharacterValue();
}
else
{
in.clear();
if (out)
(*out) << "Invalid value. Please try again." << std::endl;
else
throw InvalidValue("ReadValue: Invalid value found with no out stream.");
continue;
}
}
success = true;
}
return input;
}
示例3: numLines
int Cluster::numLines(std::istream & in)
{
//save position of file pointer
int pos = in.tellg();
// account for possible eof bit
in.clear();
// move file pointer to beginning of file
in.seekg(0);
std::string aString; //holds unused information
int lines = 0; //counts lines
while (getline(in, aString))
lines++;
// clear eof bit
in.clear();
// recover previous position in file
in.seekg(pos);
return lines;
}
示例4: readEleNumberOfElementsIncorrectException
// public function: documentation in corresponding .h file
readEleFile::readEleFile(std::istream &input) {
// read number of elements
int numElements = -1;
input >> numElements;
// guard: check for invalid input
if (!input.good() || numElements < 0) {
throw readEleNumberOfElementsIncorrectException();
}
// drop 2 integer values
int drop;
input >> drop >> drop;
// initialize duplicate-check-array
bool *defined = new bool[numElements];
for (int i = 0; i < numElements; i++) {
defined[i] = false;
}
// create array and fill it
m_elements = new tetrahedron[numElements];
for (int i = 0; i < numElements; i++) {
// read index
int index;
input >> index;
// guard: check for invalid index
if (!input.good() || index < 1 || index > numElements) {
input.clear(); // repair stream so that it can tell us its position
throw readEleElementIndexIncorrectException(input.tellg(), numElements);
}
// guard: check, if element already defined
if (defined[index - 1]) {
throw readEleElementAlreadyDefinedException(input.tellg(), index);
}
// read tetrahedron
input >> m_elements[index - 1];
defined[index - 1] = true;
// guard: check for invalid points
if (!input.good() || m_elements[index - 1].m_cornerA < 1 || m_elements[index - 1].m_cornerB < 1
|| m_elements[index - 1].m_cornerC < 1 || m_elements[index - 1].m_cornerD < 1) {
input.clear(); // repair stream so that it can tell us its position
throw readElePointIndicesIncorrectException(input.tellg(), index);
}
// adapt indices (with tetgen they start at 1)
m_elements[index - 1].m_cornerA--;
m_elements[index - 1].m_cornerB--;
m_elements[index - 1].m_cornerC--;
m_elements[index - 1].m_cornerD--;
}
m_elementsReader = new staticArrayReader<tetrahedron>(m_elements, numElements);
delete[] defined;
}
示例5: readBlocks
static uint64_t readBlocks(std::istream & in, uint64_t const indexpos)
{
in.clear();
in.seekg(indexpos,std::ios::cur);
uint64_t blocks;
libmaus::serialize::Serialize<uint64_t>::deserialize(in,&blocks);
in.clear();
in.seekg(-static_cast<int64_t>(sizeof(uint64_t)),std::ios::cur);
in.seekg(-static_cast<int64_t>(indexpos),std::ios::cur);
return blocks;
}
示例6:
void Polynomial<T>::input(std::istream &in)
{
T coef;
int data;
in.clear();
in>>coef>>data;
while(in.good())
{
operator+=(Polynomial(coef,data));
in>>coef>>data;
}
in.clear();
in.get();
}
示例7: gene
int
GA3DBinaryStringGenome::read(std::istream & is)
{
static char c;
unsigned int i=0, j=0, k=0;
do{
is >> c;
if(isdigit(c)){
gene(i++, j, k, ((c == '0') ? 0 : 1));
if(i >= nx){
i=0;
j++;
}
if(j >= ny){
j=0;
k++;
}
}
} while(!is.fail() && !is.eof() && k < nz);
_evaluated = gaFalse;
if(is.eof() &&
((k < nz) || // didn't get some lines
(j < ny && j != 0) || // didn't get some lines
(i < nx && i != 0))){ // didn't get some lines
GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
is.clear(std::ios::badbit | is.rdstate());
return 1;
}
return 0;
}
示例8: ignoreCommentLines
void reader_utility::ignoreCommentLines(std::istream& stream, const std::string& lineHead)
{
if (stream.fail() || stream.eof()) return;
std::istream::pos_type pos = stream.tellg();
std::string peekStr;
while (stream >> peekStr) {
int strSize = lineHead.size();
bool commentFound = (static_cast<int>(peekStr.size()) >= strSize &&
peekStr.substr(0, strSize) == lineHead);
if (commentFound) {
ignoreLine(stream);
pos = stream.tellg();
}
else {
stream.seekg(pos, std::ios_base::beg);
return;
}
}
if (stream.eof()) {
stream.clear();
stream.seekg(pos, std::ios_base::beg);
}
}
示例9: Read
void SymbolTable::Read(std::istream& i, bool quiet)
{
// get entries from stream
// assume POSIX nm format: <sym> <type> <addr> <size(opt)>
size_t nread = 0;
while (!i.eof())
{
MemAddr addr;
size_t sz;
string sym, ty;
i.clear();
i >> sym >> ty >> hex >> addr;
if (!i.good()) break;
i >> sz;
if (!i.good()) sz = 0;
m_entries.push_back(make_pair(addr, make_pair(sz, sym)));
++nread;
}
if (!quiet)
{
if (!nread)
cerr << "Warning: symbol table is empty (no symbols read)." << endl;
else
clog << "Symbol table: " << dec << nread << " symbols loaded." << endl;
}
sort(m_entries.begin(), m_entries.end());
m_cache.clear();
}
示例10: seek
void seek(size_t pos)
{
inf->clear();
inf->seekg(pos);
if(inf->fail())
fail("seek error");
}
示例11: getSparseCount
static uint64_t getSparseCount(std::istream & CIS)
{
CIS.clear();
CIS.seekg(0,std::ios::end);
uint64_t const n = CIS.tellg() / (2*sizeof(uint64_t));
return n;
}
示例12: huffmanEncode
std::string huffmanEncode(std::istream &inFile, std::map<char, long long> &char_freq, int *validBitsLastByte) {
char value;
int buffCnt;
stringstream ssFileEncoded;
vector<char> codeVector;
MyIOBitStream bitStream;
inFile.clear(); inFile.seekg(0, inFile.beg);
(*validBitsLastByte) = 8; // default : last byte has 8 bits
buffCnt = 0;
while (inFile.get(value)) {
codeVector = char_codeVector[value];
// for each bit of the code
for (int i = 0; i < codeVector.size(); i++) {
if (codeVector[i] & 1) {
bitStream.appendBit(true);
}
else {
bitStream.appendBit(false);
}
buffCnt++;
if (buffCnt == SIZEBUFFER) { // Record the buffer into the output file
ssFileEncoded << bitStream.getString();
buffCnt = 0;
}
}
}
if (buffCnt > 0) {
(*validBitsLastByte) = bitStream.getBitsWriteCounter() ? : 8;
ssFileEncoded << bitStream.getString();
}
示例13: cparse
void cparse(ConfigurationHolder & configuration_holder, std::istream & ifs) {
const size_t maxlen = 1024;
char line[maxlen];
char context[512] = { 0 };
bool truncated = false;
while (ifs.good()) {
ifs.getline(line, maxlen);
if (ifs.fail() && ifs.gcount() == (maxlen-1)) {
if (!truncated) {
LOG(LOG_INFO, "Line too long in configuration file");
hexdump(line, maxlen-1);
}
ifs.clear();
truncated = true;
continue;
}
if (truncated) {
truncated = false;
continue;
}
char * tmp_line = line;
while (isspace(*tmp_line)) tmp_line++;
if (*tmp_line == '#') continue;
char * last_char_ptr = tmp_line + strlen(tmp_line) - 1;
while ((last_char_ptr >= tmp_line) && isspace(*last_char_ptr)) last_char_ptr--;
if (last_char_ptr < tmp_line) continue;
*(last_char_ptr + 1) = '\0';
//LOG(LOG_INFO, "Line='%s'", tmp_line);
this->parseline(configuration_holder, tmp_line, context);
};
}
示例14: fullread
std::streamsize fullread(
std::istream& istr,
char* buf,
std::streamsize requested)
{
std::streamsize got;
std::streamsize total = 0;
istr.read(buf, requested); /*Flawfinder: ignore*/
got = istr.gcount();
total += got;
while(got && total < requested)
{
if(istr.fail())
{
// If bad is true, not much we can doo -- it implies loss
// of stream integrity. Bail in that case, and otherwise
// clear and attempt to continue.
if(istr.bad()) return total;
istr.clear();
}
istr.read(buf + total, requested - total); /*Flawfinder: ignore*/
got = istr.gcount();
total += got;
}
return total;
}
示例15: readEntry
IndexEntry readEntry(std::istream & indexistr, uint64_t const entryid) const
{
uint64_t const entrybitpos = getEntryBitPos(entryid);
uint64_t const entrybytepos = entrybitpos>>3;
uint64_t const entrybitoff = entrybitpos - (entrybytepos<<3);
// seek to index position
indexistr.clear();
indexistr.seekg(entrybytepos,std::ios::beg);
if ( static_cast<int64_t>(indexistr.tellg()) != static_cast<int64_t>(entrybytepos) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Failed to seek to index position " << entrybytepos << " in file " << filename << " of size "
<< ::libmaus2::util::GetFileSize::getFileSize(filename) << std::endl;
se.finish();
throw se;
}
::libmaus2::bitio::StreamBitInputStream SBIS(indexistr);
SBIS.read(entrybitoff);
uint64_t const pos = SBIS.read(posbits);
uint64_t const kcnt = SBIS.read(kbits);
uint64_t const vcnt = SBIS.read(vbits);
return IndexEntry(pos,kcnt,vcnt);
}