本文整理汇总了C++中istream::setstate方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::setstate方法的具体用法?C++ istream::setstate怎么用?C++ istream::setstate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类istream
的用法示例。
在下文中一共展示了istream::setstate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: safeGetline
void safeGetline(istream& is, string& t)
{
t.clear();
std::istream::sentry se(is, true);
std::streambuf* sb = is.rdbuf();
while (true)
{
int c = sb->sbumpc();
switch (c)
{
case '\n':
return;
case '\r':
if (sb->sgetc() == '\n')
sb->sbumpc();
return;
case EOF:
if (t.empty())
is.setstate(std::ios::eofbit);
return;
default:
t += (char)c;
}
}
}
示例2: catch
Triangle::Triangle(istream& is) {
try {
is >> get<0>(vertices_) >> get<1>(vertices_) >> get<2>(vertices_);
} catch (string s) {
is.setstate(ios_base::failbit);
cout << s << endl;
}
}
示例3: input
//-----------------------------------------------------------------------------
// Class: CTime
// Method: void CTime::input(istream& sin)
// Description: input method for CTime objects
// Input: sin
// Called By: constructor from DateTime/CTime, mutators, saferead
// Parameters: istream& sin - input istream
// Returns: n/a
// History Log:
// 4/29/15 KG completed version 1.0
// ----------------------------------------------------------------------------
void CTime::input(istream& sin)
{
int hour = 0;
int minute = 0;
int second = 0;
m_hour = hour;
m_second = second;
m_minute = minute;
char c = ' ';
sin.get(c);
if(c == '\n') //checks for no input if datetime
{
sin.putback(c);
return;
}
sin.putback(c); //puts back character if normal input
if(sin >> hour)
{
if(hour > MINTIME && hour <= MAXHOUR)
m_hour = hour;
sin.get(c);
if(c == '\n')
{
sin.putback(c);
return;
}
if(c == ':')
{
if(sin >> minute)
{
if(minute > MINTIME && minute < MAXMINSEC)
{
m_minute = minute;
}
sin.get(c);
if(c == '\n')
{
sin.putback(c);
return;
}
if(c == ':')
{
if(sin >> second)
{
if(second > MINTIME && second < MAXMINSEC)
{
m_second = second;
}
}
}
else
sin.setstate(std::ios::failbit);
}
}
else
示例4: OfGtpStream
Player Player::OfGtpStream (istream& in) {
string s;
in >> s;
if (!in) return Invalid ();
if (s == "b" || s == "B" || s == "Black" || s == "BLACK "|| s == "black") {
return Black();
}
if (s == "w" || s == "W" || s == "White" || s == "WHITE "|| s == "white") {
return White();
}
in.setstate (ios_base::badbit); // TODO undo read?
return Invalid();
}
示例5: ReadDisplaySettings
void GLUINavigationProgram::ReadDisplaySettings(istream& in)
{
int dx,dy,dw,dh;
dx = viewport.x; dy = viewport.y;
dw = width-viewport.w; dh = height-viewport.h;
in>>viewport;
string str;
in>>str;
if(str != "ORBITDIST") { in.setstate(ios::badbit); return; }
in>>camera.dist;
camera.fromCamera(viewport,camera.dist);
glutReshapeWindow(viewport.w+dw+dx,viewport.h+dh+dy);
}
示例6: from_string_vec
void from_string_vec(istream & sstr, vector<T> & vecValue)
{
T value;
while (isspace(sstr.peek()))
sstr.get();
int c = sstr.get();
if (c!='[') {
sstr.setstate(ios::failbit);
return;
}
while (isspace(sstr.peek()))
sstr.get();
c = sstr.peek();
if (c==']') {
sstr.get();
return;
}
sstr >> value;
if (!sstr)
return;
vecValue.push_back(value);
while(true) {
while (isspace(sstr.peek()))
sstr.get();
c = sstr.get();
if (c!=',' && c!=']') {
sstr.setstate(ios::failbit);
return;
}
if (c==']')
return;
sstr >> value;
if (!sstr)
return;
vecValue.push_back(value);
}
}
示例7:
template <> _UCXXEXPORT string _readToken<char, char_traits<char> >(istream & stream)
{
string temp;
char_traits<char>::int_type c;
while(true){
c = stream.rdbuf()->sgetc();
if(c != char_traits<char>::eof() && isspace(c) == false){
stream.rdbuf()->sbumpc();
temp.append(1, char_traits<char>::to_char_type(c));
}else{
break;
}
}
if (temp.size() == 0)
stream.setstate(ios_base::eofbit|ios_base::failbit);
return temp;
}
示例8: ReadOneRecord
void ReadOneRecord(istream& in, value& val)
{
if (in.peek() != '{') { // bail if not at record start
in.setstate(ios::failbit); // set stream failure, so we can detect it
return;
}
in.ignore(1024, '\n');
while (true) {
string line;
getline(in, line, '\n');
istringstream istr(line.c_str());
if (istr.peek() == '}') break;
std::pair<string, value> entry;
ReadFieldname(istr, entry.first);
ReadValue(istr, entry.second);
cout << "pair<attribute : value> = <" << entry.first << " : "
<< entry.second << ">" << endl;
}
}
示例9: getMyNum
int getMyNum(istream& is,char delim,bool & emptyFlag,bool & delimFlag,bool allowWS=false) // deliminator is '/' or '\n'
{
stringstream ss;
bool foundFirst=false;
delimFlag=false; //ensure it starts out FALSE
char c='0';
int myNum=-99; // init number
is>>ws; // built in skip leading whitespace
//while(is.get(c) && !(delimFlag=delimFound(c,delim)) && c!=sysEOL)//c!=delim)
while(is.get(c) && !(delimFlag=delimFound(c,delim)) && c!=sysEOL)//c!=delim)
{
//cout<<":"<<c<<":"<<endl;
//cout<<"!"<<is.tellg()<<"!"<<endl;
if((!foundFirst)&& c=='-') //check for a leading negative
{
ss<<c; //first char can b negative (-)
foundFirst=true;
}
else if(!isIntChar(c))
{
if(!( allowWS && isWhiteSpaceChar(c))) // TODO could be combined w/ above if?
{
//TODO do not strip \n
is.ignore(256,delim); // fails for >256 chars, okay by me
is.setstate(ios::failbit);
delimFlag=true;
}
}
else
{
foundFirst=true; //set found first, if no negative and
ss<<c;
}
}
// get size
/*
ss.seekg(0,ios::end);
int size=ss.tellg();
ss.seekg(0,ios::beg);
*/
int size=ss.str().size();
if( size==0 ||(size=1 && ss.str()=="-")) // check for empty, or single '-'
{
emptyFlag=true;
}
ss>> myNum; //stuff result into an int
/*
if(is.fail()&& !allowWS) // kluge 12 3/345 doesnt => 12
{
cout <<"magic3"<<endl;
is.unget();
is.putback(delim);
}
*/
if(delim != sysEOL && is.peek()==sysEOL) //kluge for 88/<LF>, otherwise grabs next line
{
cout <<"Magic2"<<endl;
is.unget();
}
if(delim== sysEOL || c== sysEOL) // put back EOL or (c == sysEOL) kinda duplication
//if(c== sysEOL&&(emptyFlag&&delim==sysEOL)) // put back EOL or (c == sysEOL) kinda duplication
{
//cout<<"putting LF back"<<endl;
is.unget();
}
//kluge
if( emptyFlag && delim == sysEOL) // check for empty, or single '-' for case of 7 <lf>, is.get(c) processed before delimFlag=delimFound...
{
is.unget();
delimFlag=true;
cout <<"Magic set flag"<<endl;
myNum=1;
}
is.clear(); //clear all flags
return myNum;
}