本文整理汇总了C++中istream::putback方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::putback方法的具体用法?C++ istream::putback怎么用?C++ istream::putback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类istream
的用法示例。
在下文中一共展示了istream::putback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getString
string SceneLoader::getString(istream &str)
{
string ret;
char temp;
str >> temp; // get rid of white space, get to first char
str.putback(temp);
while (str.get(temp))
{
if (temp >= 'a' && temp <= 'z'
|| temp >= 'A' && temp <= 'Z'
|| temp >= '0' && temp <= '9'
|| temp == '_' )
{
ret += temp;
}
else if (temp == '#')
{
string no;
getline(str, no);
if (ret.empty())
return getString(str);
else
return ret;
}
else {
str.putback(temp);
break;
}
}
return ret;
}
示例2: ReadNumber
XFileToken XFileToken::ReadNumber(istream& s)
{
XFileToken result;
result.m_type = Integer;
char c;
s.get(c);
result.m_content.push_back(c);
while (s.get(c))
{
if (c == '.')
{
if (result.m_type == Integer)
result.m_type = Float;
else
{
s.putback(c);
return result;
}
}
else if (!isdigit(c))
{
s.putback(c);
return result;
}
result.m_content.push_back(c);
}
return result;
}
示例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: _check_idlabel_title
bool _check_idlabel_title(istream &s, string &title)
{
title.clear();
if (!s.good())
return false;
bool hv = false;
while (1)
{
string line0;
getline(s, line0);
if (!allSpace(line0))
{
string line = removeLeadSpace2(line0);
if (line.length() <= 1 || !(
(line.front() == '"' && line.back() == '"')
|| (line.front() == '\'' && line.back() == '\'')
|| (line.front() == '(' && line.back() == ')')
))
{
if (!s.eof())
s.putback('\n');
s.clear();
strputback(s, line0);
return hv;
}
title = line.substr(1, line.length() - 2);
return true;
}
if (s.eof() || hv)
break;
hv = true;
}
return true;
}
示例5: while
bool
//
// Extracts the next word from the input stream. This function has the same
// functionality as "cin >> word", excepts it additionally makes sure that
// the word buffer is not over-run!
//
getWord(istream& in, string& word)
{
int i = 0;
char ch;
word = "";
while(in.get(ch))
{
if(!isspace(ch)) {
if(i > MAX_WORDLEN) {
in.putback(ch);
break;
} else {
word += ch;
i++;
}
}
else {
break;
}
}
if (i > 0)
return true;
else
return false;
}
示例6: predicate_scan_token
string predicate_scan_token ( istream & is, scan_token_predicate & prd )
{
char ch = '\0';
string res = "";
do { // eat whitespaces ...
ch = is.get();
} while ( isspace( ch ) );
for( bool longString = false;; ch = is.get() )
{
if( ch == DOUBLE_L )
{
if( longString )
break;
else
longString = true;
}
else if( longString )
res += ch;
else if( prd.check( ch ) )
{
if( res.size() )
is.putback( ch );
else
res += ch;
break;
}
else
res += ch;
}
return res;
}
示例7: SkipComments
bool XFileToken::SkipComments(istream& s)
{
char c;
SkipWS(s);
while (s.get(c))
{
if (c == '/')
{
if (!s.get(c))
THROW_EXCEPTION_T("Parsing error", ParsingException);
if (c != '/')
THROW_EXCEPTION_T("Parsing error", ParsingException);
}
else if (c != '#')
{
s.putback(c);
return true;
}
while (s.get(c))
{
if (c == '\n')
break;
}
SkipWS(s);
}
return false;
}
示例8: scan_pgn
int ChessIO::scan_pgn(istream &game_file, vector<string> &contents)
{
Board board;
int c;
while (game_file.good() && !game_file.eof())
{
// Collect the header:
long first;
vector<Header> hdrs;
string eventStr;
collect_headers(game_file, hdrs, first);
if (get_header(hdrs,"Event",eventStr))
{
// We have the headers, munge them into a single-line game
// description. Append the index to the game so the GUI
// can navigate to the game when the user clicks on the
// description.
string descr;
get_game_description(hdrs, descr, first);
contents.push_back(descr);
}
hdrs.clear();
while (game_file.good() && !game_file.eof())
{
if ((c = game_file.get()) == '[')
{
game_file.putback(c);
break;
}
}
}
return 1;
}
示例9: eof
bool eof(istream& in)
{
char ch;
in >> ch;
in.putback(ch);
return !in;
}
示例10: read_header
void read_header(istream& fin, ostream& fout, int& width, int& height, int& max)
{
char header[100];
char ch;
// Getmage=ic number
fin.getline(header,100);
// write magic number
fout << header <<endl;
cout << header << endl;
// get all comment lines and write to new file
fin >> ch;
while (ch == '#')
{
fin.getline(header, 100);
fout <<ch << header << endl;
cout <<ch << header << endl;
fin >> ch;
}
fin.putback(ch);
// Input width and height of image
fin >> width >> height;
cout << width <<" " << height << endl;
fout << width <<" " << height << endl;
// Input maximum color value
fin >> max;
cout << max << endl;
fout << max << endl;
return;
}
示例11: FromStream
void CL_TimeOfDay::FromStream (istream& s)
{
CL_String rep;
char c;
long count = 0;
char fill_char = s.fill ();
while (s.get (c) && c == fill_char);
if (!s.good() || s.eof()) {
_numSecs = 0;
return;
}
do {
if (isalnum (c) || c == ':') {
rep.Append (c);
count++;
}
else
break;
} while (s.get (c));
long n = ParseAndConvert (rep);
if (n > 0) {
if (!s.eof())
s.putback (c);
_numSecs = n;
}
else {
s.seekg (s.tellg() - count, istream::cur);
_numSecs = 0;
}
}
示例12: skipspace
/******************************************************************************************
void skipspace(istream& in)
Description:
This function reads past all whitespace (ie. ' ' and '/t').
Parameters:
istream& in -input stream being read
******************************************************************************************/
void skipspace(istream& in)
{
char ch;
in.get(ch);
while ((ch ==' ') ||(ch =='\t'))
in.get(ch);
in.putback(ch);
}
示例13: seek_eoln
int seek_eoln(istream &i)
{
char ch=' ';
int ret=0;
while ( (i) && (ch==' ') ) i.get(ch);
if (ch=='\n') ret=1;
else if (i) i.putback(ch);
if (!i) ret=1;
return ret;
};
示例14: seek_eof
int seek_eof(istream &i)
{
char ch=' ';
int ret=0;
while ( (i) && ((ch==' ') || (ch=='\n')) ) i.get(ch);
// if (ch==0) return 1;
if (i) { i.putback(ch);}
if (!i) ret=1;
return ret;
};
示例15: putback
// Put a string back into an istream
void a::putback(istream &in, const string &s) {
if (s.length()==0)
return;
unsigned i=unsigned(s.length())-1;
while (true) {
in.putback(s[i]);
if (i==0)
return;
i--;
}
}