本文整理汇总了C++中std::ifstream::putback方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::putback方法的具体用法?C++ ifstream::putback怎么用?C++ ifstream::putback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::putback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: elemCount
GeometryLoaderDX11::PlyElementDesc GeometryLoaderDX11::ParsePLYElementHeader(std::string headerLine, std::ifstream& input)
{
GeometryLoaderDX11::PlyElementDesc desc;
std::string txt;
// Parse the header line
// "element <name> <count>"
int split = headerLine.find_first_of(' ', 8);
desc.name = headerLine.substr(8, split - 8);
split = headerLine.rfind( ' ' );
std::istringstream elemCount(headerLine.substr(split, headerLine.length() - split));
elemCount >> desc.elementCount;
// Parse any attached properties
while(input.is_open() && !input.eof())
{
std::getline( input, txt );
if(0 == txt.compare(0, 13, "property list"))
{
// Parse this property list declaration
desc.dataFormat.push_back(ParsePLYElementPropertyList(txt.substr(14, txt.length() - 14)));
}
else if(0 == txt.compare(0, 8, "property"))
{
// Parse this property declaration
desc.dataFormat.push_back(ParsePLYElementProperty(txt.substr(9, txt.length() - 9)));
}
else
{
// At this point we'll also have read a line too far so
// need to "unread" it to avoid breaking remaining parsing.
input.putback('\n');
for(int i = -1 + txt.length(); i >= 0; i--)
input.putback(txt.at(i));
// (there must be a better way, no?!?)
break;
}
}
return desc;
}
示例2:
// reads until first non-whitespace character
void MD5Model::skipWhitespace(std::ifstream &fin) {
char c = '\0';
while (!fin.eof()) {
fin.get(c);
if (!IS_WHITESPACE(c)) {
fin.putback(c);
break;
}
}
}
示例3: readIntList
static void readIntList(std::vector<unsigned>& ints, std::ifstream& i) {
std::string tok;
while (i.good()) {
i >> tok;
if (isInt(tok)) {
ints.push_back(atoi(tok.c_str()));
} else {
for (unsigned j=tok.size(); j>0; --j)
i.putback(tok[j-1]);
break;
}
}
}
示例4: Exception
void MD5Model::skipComments(std::ifstream &fin) {
char c;
fin.get(c);
if (c != '/')
throw Exception("MD5Model::skipComments(): invalid comment, expected //");
while (!fin.eof() && c != '\n')
fin.get(c);
// put back last character read
fin.putback(c);
}
示例5: readDummy
void MovingMeshFB::readDummy(std::ifstream& is)
{
char c;
for (is.get(c);true;is.get(c)) {
if (c == '#') {
while (true) {
is.get(c);
if (c == '#') break;
}
}
else if (('0' <= c && c <= '9')||(c == '.')||(c =='-'))
break;
}
is.putback(c);
}
示例6: read_next_number
uint32_t read_next_number( std::ifstream & is ) {
uint32_t value = 0;
// Skip whitespace
char c;
while( ( is.get(c) ) && (c == ' ' || c == '\t' || c=='\n' || c == '\r' ) );
while( c >= '0' && c <= '9' ) {
value *= 10;
value += ( c - '0' );
is.get(c);
}
is.putback(c);
return value;
}
示例7: pnm_read
void pnm_read(std::ifstream &file, char *buf)
{
char doc[PNM_BUFFER_SIZE];
char c;
file >> c;
while (c == '#') {
file.getline(doc, PNM_BUFFER_SIZE);
file >> c;
}
file.putback(c);
file.width(PNM_BUFFER_SIZE);
file >> buf;
file.ignore();
}
示例8: passWhiteSpaces
inline void FileParse::passWhiteSpaces(std::ifstream& fin) {
// Check for eof
if (fin.eof()) return;
char c;
// Get first character
fin.get(c);
// Loop
while (!fin.eof()) {
if (c==' ' || c=='\n' || c=='\r');
else { // Encountered a non-whitespace
fin.putback(c);
return;
}
// Get next character
fin.get(c);
}
}
示例9: passSpaces
inline bool FileParse::passSpaces(std::ifstream& fin) {
char c;
// Get first character
fin.get(c);
// Loop
while (!fin.eof()) {
if (c==' ');
else if (c=='\n' || c=='\r') return true;
else { // Encountered a non-whitespace
fin.putback(c);
return false;
}
// Get next character
fin.get(c);
}
// Return success
return true;
}
示例10: getBody
inline void FileParse::getBody(std::ifstream& fin) {
// Look for heads
char c;
bool end = false;
while (!fin.eof() && !end) {
passWhiteSpaces(fin);
if (!fin.eof()) fin.get(c);
else return;
if (c=='}') // End of a body
return;
else if (c=='/') { // Could be the start of a comment
checkComment(fin);
}
else {
fin.putback(c);
getHead(fin);
}
}
}
示例11: passComment
inline void FileParse::passComment(std::ifstream& fin, bool mline) {
string comment;
// Start right after "//" or "/*"
char c;
fin.get(c);
while (!fin.eof()) {
if (mline && c=='*') {
fin.get(c);
if (fin.eof()) {
// Message
message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n");
message += "--> EOF\n";
// End of file encountered
return; // Check end of file
}
if (c=='/') {
// Message
message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n");
// End of the comment
return;
}
else message += ('*' + c);
}
else if (c=='\n' || c=='\r') {// Single line comments end with at newline
if (mline) comment += "[\\n]";
else {
// Message
message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n");
// In case a newline signifies something for whoever called this function
fin.putback(c);
return;
}
}
else {
if (c=='\t') comment += "[\\t]";
else comment.push_back(c);
}
// Get next character
fin.get(c);
}
}
示例12: ReadOpenClosePar
void CFileSystemLongArray::ReadLongArray2D( std::ifstream &stream,
unsigned int nx, unsigned int ny, long *pdata )
{
std::string buffer;
while ( ReadOpenClosePar( stream ) != 0 )
{
ReadString( stream, buffer ); // str
if ( g_verbose > 1)
{
std::cout << "Read token <" << buffer << ">\n";
}
switch( token_match( buffer, token_list, token_num ) )
{
case TOKEN_YSLICE:
if ( g_verbose > 1 )
{
std::cout << "Reading Y-slice\n";
}
ReadLongArray1D( stream, nx, pdata );
pdata += nx;
break;
default:
std::cout << "ReadLongArray2D::Unknown token <";
std::cout << buffer.c_str() << " >\n";
break;
}
ReadClosePar( stream ); // }
}
stream.putback( '}' );
}
示例13: ReadFile
int CExtensionHeaderFileSettingsIODataAsciiIO::ReadFile( std::ifstream &stream )
{
int result;
std::string tokenid;
int entry_savedstates;
result = true;
if ( g_verbose )
{
std::cout << "Reading CExtensionHeaderFileSettingsIODataAsciiIO" << std::endl;
}
while ( ReadOpenClosePar( stream ) != 0 )
{
ReadString( stream, tokenid );
if ( g_verbose > 1 )
{
std::cout << "Read Token = <" << tokenid << ">\n";
}
switch( token_match( tokenid, token_list, token_num ) )
{
case TOKEN_SYSTEMLIST:
m_systemlist.ReadFile( stream );
if ( g_verbose )
{
std::cout << "Read <systemlist>\n";
}
break;
case TOKEN_NEWLIST:
m_newlist.ReadFile( stream );
if ( g_verbose )
{
std::cout << "Read <newlist>\n";
}
break;
case TOKEN_IGNORELIST:
m_ignorelist.ReadFile( stream );
if ( g_verbose )
{
std::cout << "Read <ignorelist>\n";
}
break;
case TOKEN_VENDORLIST:
m_vendorlist.ReadFile( stream );
if ( g_verbose )
{
std::cout << "Read <vendorlist>\n";
}
break;
case TOKEN_VERSIONLIST:
m_versionlist.ReadFile( stream );
if ( g_verbose )
{
std::cout << "Read <versionlist>\n";
}
break;
case TOKEN_SAVEDSTATES:
ReadInteger( stream, entry_savedstates );
m_savedstates = entry_savedstates;
if ( g_verbose )
{
std::cout << "Read <savedstates> = <" << entry_savedstates << ">\n";
}
break;
default:
std::cout << "CExtensionHeaderFileSetIO::Unknown token <" << tokenid << ">\n";
break;
}
ReadClosePar( stream );
}
stream.putback( '}' );
if ( g_verbose )
{
std::cout << "Reading complete." << std::endl << std::endl;
}
return( result );
}
示例14: nData_records
/**!
* The function loads ASCII file header and tries to identify the type of the
*header.
* Possible types are
* SPE, PAR or PHS
*
* if none three above identified, returns "undefined" type
* it also returns the FileTypeDescriptor, which identifyes the position of the
*data in correcponding ASCII file
* plus characteristics of the data extracted from correspondent data header.
*/
FileTypeDescriptor
FindDetectorsPar::get_ASCII_header(std::string const &fileName,
std::ifstream &data_stream) {
std::vector<char> BUF(1024);
FileTypeDescriptor file_descriptor;
file_descriptor.Type = NumFileTypes; // set the autotype to invalid
data_stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
if (!data_stream.is_open()) {
g_log.error() << " can not open existing ASCII data file: " << fileName
<< std::endl;
throw(Kernel::Exception::FileError(" Can not open existing input data file",
fileName));
}
// let's identify the EOL symbol; As the file may have been prepared on
// different OS, from where you are reading it
// and no conversion have been performed;
char symbol;
data_stream.get(symbol);
while (symbol > 0x1F) {
data_stream.get(symbol);
}
char EOL;
if (symbol == 0x0D) { // Win or old Mac file
data_stream.get(symbol);
if (symbol == 0x0A) { // Windows file
EOL = 0x0A;
} else { // Mac
EOL = 0x0D;
data_stream.putback(symbol);
}
} else if (symbol == 0x0A) { // unix file.
EOL = 0x0A;
} else {
g_log.error()
<< " Error reading the first row of the input ASCII data file: "
<< fileName << " as it contains unprintable characters\n";
throw(Kernel::Exception::FileError(" Error reading the first row of the "
"input ASCII data file, as it contains "
"unprintable characters",
fileName));
}
file_descriptor.line_end = EOL;
data_stream.seekg(0, std::ios::beg);
get_my_line(data_stream, &BUF[0], BUF.size(), EOL);
if (!data_stream.good()) {
g_log.error() << " Error reading the first row of the input data file "
<< fileName << ", It may be bigger then 1024 symbols\n";
throw(Kernel::Exception::FileError(" Error reading the first row of the "
"input data file, It may be bigger then "
"1024 symbols",
fileName));
}
// let's find if there is one or more groups of symbols inside of the buffer;
int space_to_symbol_change = count_changes(&BUF[0], BUF.size());
if (space_to_symbol_change >
1) { // more then one group of symbols in the string, spe file
int nData_records(0), nData_blocks(0);
// cppcheck-suppress invalidscanf
int nDatas = sscanf(&BUF[0], " %d %d ", &nData_records, &nData_blocks);
file_descriptor.nData_records = (size_t)nData_records;
file_descriptor.nData_blocks = (size_t)nData_blocks;
if (nDatas != 2) {
g_log.error() << " File " << fileName << " iterpreted as SPE but does "
"not have two numbers in the "
"first row\n";
throw(Kernel::Exception::FileError(" File iterpreted as SPE but does not "
"have two numbers in the first row",
fileName));
}
file_descriptor.Type = SPE_type;
get_my_line(data_stream, &BUF[0], BUF.size(), EOL);
if (BUF[0] != '#') {
g_log.error()
<< " File " << fileName
<< "iterpreted as SPE does not have symbol # in the second row\n";
throw(Kernel::Exception::FileError(
" File iterpreted as SPE does not have symbol # in the second row",
fileName));
}
file_descriptor.data_start_position =
data_stream.tellg(); // if it is SPE file then the data begin after the
// second line;
} else {
file_descriptor.data_start_position =
data_stream.tellg(); // if it is PHX or PAR file then the data begin
//.........这里部分代码省略.........
示例15: if
// reads in next token from file and matches it to a token type,
// if tokStr is non-NULL then it will be set to the text of the token
MD5Model::TOKEN MD5Model::getNextToken(std::ifstream &fin, std::string *tokStr) {
skipWhitespace(fin);
std::string str;
TOKEN t = TOKEN_INVALID;
while (!fin.eof()) {
char c = '\0';
fin.get(c);
// single character tokens
if ('{' == c || '}' == c || '(' == c || ')' == c) {
// if already reading in a token, treat this as a delimiter
if (t != TOKEN_INVALID) {
fin.putback(c);
if (tokStr != NULL)
(*tokStr) = str;
}
if ('{' == c)
t = TOKEN_LBRACE;
if ('}' == c)
t = TOKEN_RBRACE;
if ('(' == c)
t = TOKEN_LPAREN;
if (')' == c)
t = TOKEN_RPAREN;
if (tokStr) {
(*tokStr) = std::string();
(*tokStr) += c;
}
return t;
}
if (isdigit(c)) {
str += c;
if (TOKEN_INVALID == t)
t = TOKEN_INT;
else if (t != TOKEN_INT && t != TOKEN_FLOAT && t != TOKEN_KEYWORD) {
std::string msg("MD5Model::getNextToken(): invalid token '");
msg += str + "'";
throw Exception(msg);
}
}
if ('-' == c) {
str += c;
if (TOKEN_INVALID == t)
t = TOKEN_INT;
else {
std::string msg("MD5Model::getNextToken(): invalid token '");
msg += str + "'";
throw Exception(msg);
}
}
if (isalpha(c)) {
str += c;
if (TOKEN_INVALID == t)
t = TOKEN_KEYWORD;
else if (t != TOKEN_KEYWORD) {
std::string msg("MD5Model::getNextToken(): invalid token '");
msg += str + "'";
throw Exception(msg);
}
}
if ('"' == c) {
// treat as a delimeter if already reading in a token
if (t != TOKEN_INVALID) {
fin.putback(c);
if (tokStr != NULL)
(*tokStr) = str;
return t;
}
readString(fin, str);
if (tokStr != NULL)
(*tokStr) = str;
return TOKEN_STRING;
}
if ('.' == c) {
str += c;
if (t != TOKEN_INT) {
std::string msg("MD5Model::getNextToken(): invalid token '");
msg += str + "'";
throw Exception(msg);
}
t = TOKEN_FLOAT;
}
if ('/' == c) {
// treat as a delimeter if already reading in a token
if (t != TOKEN_INVALID) {
if (tokStr != NULL)
(*tokStr) = str;
return t;
}
skipComments(fin);
skipWhitespace(fin);
//.........这里部分代码省略.........