本文整理汇总了C++中istream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::fail方法的具体用法?C++ istream::fail怎么用?C++ istream::fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类istream
的用法示例。
在下文中一共展示了istream::fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_delimited
void read_delimited(istream& is, string& s)
/* PURPOSE: Read a "" delimited string (including spaces)
from a stream. Embedded " and \ are quoted by \
*/
{ char ch;
s = "";
is >> ch;
if (ch != '"') { is.clear(ios::failbit); return; }
const int BUFSIZE = 80;
char buffer[BUFSIZE];
int i = 0;
for(;;)
{ ch = is.get();
if (is.fail()) return; // expect closing "
if (ch == '"') { buffer[i] = 0; s += buffer; return; }
if (ch == '\\')
{ ch = is.get(); // \ is escape for embedded "
if (is.fail()) return; // expect escapee
}
buffer[i] = ch;
i++;
if (i >= BUFSIZE - 1)
{ buffer[i] = 0;
s += buffer;
i = 0;
}
}
}
开发者ID:schulzmarc,项目名称:Loyola-University-Chicago---Computer-Science-272--Student-,代码行数:28,代码来源:shapes.cpp
示例2:
bool Point3Dot::load(istream &in){
coords.resize(3);
int start = in.tellg();
for(int i = 0; i < 3; i++){
in >> coords[i];
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
}
in >> theta;
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
in >> phi;
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
int typeInt;
in >> typeInt;
type = (Type)typeInt;
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
return true;
}
示例3: while
bool
fcnn::internal::read_comment(istream &is, string &s)
{
if (!is.good() || is.eof()) return false;
char c;
s.clear();
c = is.peek();
if (c != '#') return false;
is.get(c);
start_line:
do { is.get(c); }
while ((is.good() && !is.eof()) && ((c == ' ') || (c == '\t')));
if (is.eof()) return true;
if (is.fail()) return false;
while ((is) && (c != '\n')) {
s += c;
is.get(c);
}
if (is.eof()) return true;
if (is.fail()) return false;
if (c == '\n') {
if (is.peek() == '#') { s += c; goto start_line; }
else return true;
}
return true;
}
示例4: if
void
JStringManager::MergeFile
(
istream& input,
const JBoolean debug
)
{
JUInt format;
input >> format;
if (format != kASCIIFormat)
{
return;
}
JString id;
while (1)
{
input >> ws;
while (!input.eof() && input.peek() == '#') // peek() at eof sets fail()
{
JIgnoreLine(input);
input >> ws;
}
if (input.eof() || input.fail())
{
break;
}
id = JReadUntilws(input);
if (debug)
{
cout << id << endl;
}
if (input.eof() || input.fail())
{
break;
}
JString* s = new JString;
assert( s != NULL );
input >> *s;
if (input.eof() || input.fail())
{
delete s;
break;
}
if (CanOverride(id))
{
SetElement(id, s, JPtrArrayT::kDelete);
}
else if (!SetNewElement(id, s))
{
delete s;
}
}
}
示例5: readBinary
MStatus CVData::readBinary ( istream& in )
{
in.read( (char*) &_intData, sizeof(_intData) );
if ( !in.fail() ) {
in.read( (char*) &_doubleData, sizeof(_doubleData) );
} else {
return MS::kFailure;
}
return in.fail() ? MS::kFailure : MS::kSuccess;
}
示例6: read
void Point::read(istream& is)
{ char ch;
is >> ch;
if (is.fail()) return;
if (ch != '(') { is.clear(ios::failbit); return; }
is >> _x;
is >> ch;
if (is.fail()) return;
if (ch != ',') { is.clear(ios::failbit); return; }
is >> _y;
is >> ch;
if (is.fail()) return;
if (ch != ')') { is.clear(ios::failbit); return; }
}
开发者ID:schulzmarc,项目名称:Loyola-University-Chicago---Computer-Science-272--Student-,代码行数:14,代码来源:shapes.cpp
示例7: checkpoint
void Simulation::checkpoint (istream& stream, int checkpointNum) {
util::checkpoint::header (stream);
util::CommandLine::staticCheckpoint (stream);
Population::staticCheckpoint (stream);
Surveys & stream;
Global::simulationTime & stream;
Global::timeStep & stream;
simPeriodEnd & stream;
totalSimDuration & stream;
phase & stream;
(*_population) & stream;
// read last, because other loads may use random numbers:
util::random::checkpoint (stream, checkpointNum);
// Check scenario.xml and checkpoint files correspond:
int oldWUID(workUnitIdentifier);
util::Checksum oldCksum(cksum);
workUnitIdentifier & stream;
cksum & stream;
if (workUnitIdentifier != oldWUID || cksum != oldCksum)
throw util::checkpoint_error ("mismatched checkpoint");
stream.ignore (numeric_limits<streamsize>::max()-1); // skip to end of file
if (stream.gcount () != 0) {
ostringstream msg;
msg << "Checkpointing file has " << stream.gcount() << " bytes remaining." << endl;
throw util::checkpoint_error (msg.str());
} else if (stream.fail())
throw util::checkpoint_error ("stream read error");
}
示例8: while
// The read specialization takes in each number and stuffs it into the array.
int
GA1DArrayAlleleGenome<float>::read(istream & is) {
unsigned int i=0;
float val;
do{
is >> val;
if(!is.fail()) gene(i++, val);
} while(!is.fail() && !is.eof() && i < nx);
if(is.eof() && i < nx){
GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
is.clear(ios::badbit | is.rdstate());
return 1;
}
return 0;
}
示例9: end_of_loop
void end_of_loop(istream& ist, char term, const string& message) {
if(ist.fail()) {
ist.clear();
char ch;
if(ist >> ch && ch==term) return;
error(message);
}
示例10: Exception
void
// Loads pairs of words to find distances for.
LoadPairs(istream& in, vector<pairdata> &results, const bool normCase) {
pairdata temp;
cerr << "Reading in pairs from wordlist" << endl;
string lang = getLang();
while (!in.eof()){
if (in.fail()) {
throw Exception("Error Reading Input File.. Make sure it is in the correct format. Exiting\n");
}
string tempstring1 = "";
string tempstring2 = "";
in >> tempstring1 >> tempstring2;
if (tempstring1 == "---END.OF.DOCUMENT---")
break;
if ((tempstring1.length() > MAX_WORDLEN) || (tempstring2.length() > MAX_WORDLEN)) {
throw Exception("A Word was too long. Exiting\n");
}
if (normCase) {
temp.word1 = downstring(tempstring1,lang);
temp.word2 = downstring(tempstring2,lang);
} else {
temp.word1 = tempstring1;
temp.word2 = tempstring2;
}
temp.distance = 0.0;
results.push_back(temp);
}
}
示例11: transfer
streamsize cb::transfer(istream &in, ostream &out, streamsize length,
SmartPointer<TransferCallback> callback) {
char buffer[BUFFER_SIZE];
streamsize total = 0;
while (!in.fail() && !out.fail()) {
in.read(buffer, length ? min(length, BUFFER_SIZE) : BUFFER_SIZE);
streamsize bytes = in.gcount();
out.write(buffer, bytes);
total += bytes;
if (!callback.isNull() && !callback->transferCallback(bytes)) break;
if (length) {
length -= bytes;
if (!length) break;
}
}
out.flush();
if (out.fail() || length) THROW("Transfer failed");
return total;
}
示例12: while
bool SquareMaze::SquareMazeNode::readXY (istream& inData,int *x,int *y)
{
char ch;
// skip leading spaces, which are legit
while (1) {
inData.get(ch);
if (ch!=' ') {
break;
}
}
if (ch!='(') {
// not valid - probably a newline
return false;
}
inData >> *x;
if (inData.fail()) {
inData.clear();
cout << "WARNING: Solution seems to have a bad format\n";
// a bit of random, defensive programming
inData.ignore(100000,'\n'); // make sure we don't just keep reading the same thing
return false;
}
inData.get(ch);
inData >> *y;
inData.get(ch);
return true;
}
示例13: run
void run(exploder & e, istream& in)
{
// any larger, and we may try to write to a multi_frame that never has enough space
static const int BUF_SIZE = multi_frame::MAX_SIZE - frame::FRAME_SIZE;
scoped_array<char> buffer(new char[BUF_SIZE]);
ios::sync_with_stdio(false); // makes a big difference on buffered i/o
for (int line = 1; !in.eof(); ++line)
{
in.getline(buffer.get(), BUF_SIZE - 1); // leave 1 for us to inject back the newline
if (buffer[0] == '\0')
continue;
if (in.fail()) // line was too long?
{
cerr << "Skipping line <" << line << ">: line is probably too long" << endl;
in.clear(); // clear state
in.ignore(numeric_limits<streamsize>::max(), '\n');
continue;
}
buffer[in.gcount() - 1] = '\n'; // inject back the newline
buffer[in.gcount()] = '\0';
e << buffer.get();
}
}
示例14: read_double
static double read_double (istream &is) {
is.clear();
double v;
is >> v;
if (is.fail())
throw SpecialException("number expected");
return v;
}
示例15: fillStdVect
void fillStdVect (vector<student> &studentlist, istream &in_put)
{
while (!in_put.fail())
{
student* s = new student;
in_put >> *s;
if (!in_put.fail())
{
studentlist.push_back(*s);
}
else
{
delete s;
}
}
}