本文整理汇总了C++中std::ifstream::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::peek方法的具体用法?C++ ifstream::peek怎么用?C++ ifstream::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static uint32_t parse_color(std::ifstream &f,
std::string *lookahead,
uint32_t *color)
{
uint32_t i;
*color = UINT_MAX;
eat_blankspace(f);
if (f.peek() == '\n') {
return 1;
}
f >> *lookahead;
eat_blankspace(f);
if (f.peek() != '\n') {
return 1;
}
f >> *lookahead;
return 0;
}
示例2: while
static uint32_t parse_monster_color(std::ifstream &f,
std::string *lookahead,
std::vector<uint32_t> *color)
{
uint32_t i;
uint32_t c;
c = UINT_MAX;
eat_blankspace(f);
if (f.peek() == '\n') {
return 1;
}
do {
f >> *lookahead;
color->push_back(0);
eat_blankspace(f);
} while (f.peek() != '\n');
f >> *lookahead;
return 0;
}
示例3:
void ResourceManager::getI2NBlock(std::ifstream &file,
Resource::Mapping &mapping,
bool files,
const std::string &dir,
const std::string &ext)
{
uint id;
const int bufferSize = 80;
char buffer[bufferSize];
while (!file.eof() && file.peek() != '#')
{
file >> id;
if (!(file.peek() == '.'))
return;
file.ignore(2, ' ');
file.getline(buffer, bufferSize);
fixLineEnd(buffer);
if (files)
{
std::string path = dir + '/' + std::string(buffer) + ext;
Normalize(path);
mapping[id] = path;
}
else
{
mapping[id] = std::string(buffer);
}
}
}
示例4: PpmConsumeWhitespaceAndComments
void PpmConsumeWhitespaceAndComments(std::ifstream& bFile)
{
// TODO: Make a little more general / more efficient
while( bFile.peek() == ' ' ) bFile.get();
while( bFile.peek() == '\n' ) bFile.get();
while( bFile.peek() == '#' ) bFile.ignore(4096, '\n');
}
示例5: SkipComments
// Skipping lines that start with # (together with empty lines)
void SkipComments(std::ifstream& stream)
{
while (stream.peek() == '#' || stream.peek() == '\n' || stream.peek() == ' ' || stream.peek() == '\r')
{
std::string skipped;
std::getline(stream, skipped);
}
}
示例6: read_poly
void read_poly () {
int number;
is >> number;
// poly number is terminated by colon
is >> std::ws;
int colon;
if ((colon = is.get ()) != ':')
format_error ("PolyFileReader::read_poly: expected colon, got %c", colon);
// first two vertices
int initial_vertex;
is >> initial_vertex;
// translate POLY vertices into Boundary vertices
initial_vertex = lookup_vertex (initial_vertex);
int prev_vertex;
is >> prev_vertex >> std::ws;
prev_vertex = lookup_vertex (prev_vertex);
int initial_edge = b->insert_edge (Boundary::INVALID_EDGE,
initial_vertex, prev_vertex,
Boundary::INVALID_EDGE);
int prev_edge = initial_edge;
while (is_digit (is.peek ())) {
int vertex;
is >> vertex >> std::ws;
// translate POLY vertices into Boundary vertices
vertex = lookup_vertex (vertex);
int edge = b->insert_edge (prev_edge, prev_vertex,
vertex, Boundary::INVALID_EDGE);
prev_vertex = vertex;
prev_edge = edge;
}
is >> std::ws;
int closed_indic = is.peek ();
if (closed_indic == '<') {
// extract '<' character
is.get ();
// close contour
b->insert_edge (prev_edge, prev_vertex, initial_vertex, initial_edge);
} else {
std::cerr << "WARNING: non-closed contour " << number << ". this is probably not what you want.\n";
}
ignore_rest_of_line ();
}
示例7: getNextWord
void getNextWord(std::ifstream& inFile, std::string& token, std::string tokenizer, int64_t endOffSet)
{
token.clear();
char byte[1];
while(inFile.good())
{
if(inFile.tellg() >= endOffSet)
return;
byte[0] =inFile.peek();
if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
inFile.get();
}else{
break;
}
}
while(inFile.good()){
byte[0] = inFile.get();
if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
return;
}
token.append(byte,1);
}
}
示例8: wordInStr
Counter::Counter(std::ifstream &file)
{
numWords = 0;
numChars = 0;
numLines = 0;
numDigits = 0;
numLower = 0;
numUpper = 0;
lineCond = 0;
lineCond2 = 0;
std::string word;
std::string line;
//Read by word
while (file.peek() != EOF)
{
getline(file, line);
numWords += wordInStr(line);
numChars += line.length();
numDigits += numInStr(line);
numLower += lowerInStr(line);
numUpper += upperInStr(line);
if ((numInStr(line) >= 1) && (lowerInStr(line)>=1))
{
lineCond += 1;
if ((numInStr(line) >= 2) && (lowerInStr(line) >= 3))
{
lineCond2 += 1;
}
}
}
file.close();
}
示例9:
static uint32_t parse_dice(std::ifstream &f,
std::string *lookahead,
dice *d)
{
int32_t base;
uint32_t number, sides;
eat_blankspace(f);
if (f.peek() == '\n') {
return 1;
}
f >> *lookahead;
if (sscanf(lookahead->c_str(), "%d+%ud%u", &base, &number, &sides) != 3) {
return 1;
}
d->set(base, number, sides);
f >> *lookahead;
return 0;
}
示例10: make_tuple
std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
{
// Check the PPM magic number is valid
std::array<char, 2> magic_number{ { 0 } };
fs >> magic_number[0] >> magic_number[1];
ARM_COMPUTE_ERROR_ON_MSG(magic_number[0] != 'P' || magic_number[1] != '6', "Invalid file type");
ARM_COMPUTE_UNUSED(magic_number);
discard_comments_and_spaces(fs);
unsigned int width = 0;
fs >> width;
discard_comments_and_spaces(fs);
unsigned int height = 0;
fs >> height;
discard_comments_and_spaces(fs);
int max_val = 0;
fs >> max_val;
discard_comments(fs);
ARM_COMPUTE_ERROR_ON_MSG(isspace(fs.peek()) == 0, "Invalid PPM header");
fs.ignore(1);
return std::make_tuple(width, height, max_val);
}
示例11: in
/**\brief Used by testers.
*
* Not operators because that would conflict
* with the std:: operators for unsigned ints, alas.
*/
void in(std::ifstream& i, unsigned48_t& res)
{
/*
* print "0x........,0x........,0x........"
*/
union {
unsigned48_t seed;
unsigned short dummy[sizeof(unsigned48_t)/sizeof(unsigned short)];
} PUN ;
char comma = ',';
unsigned j=0;
while( (comma == ',') &&
(j < sizeof(PUN.dummy)/sizeof(unsigned short)) &&
(i >> PUN.dummy[j])
) {
if(i.peek() == ',') i >> comma;
j++;
}
if(j < sizeof(PUN.dummy)/sizeof(unsigned short) ) {
// This actually sets the badbit:
i.clear(std::ios::badbit|i.rdstate());
}
res = PUN.seed;
}
示例12: while
static uint32_t parse_object_description(std::ifstream &f,
std::string *lookahead,
std::vector<object_description> *v)
{
std::string s;
bool read_name, read_color, read_desc,
read_speed, read_dam, read_hp, read_attr,
read_type, read_dodge, read_def, read_val,
read_weight;
std::string name, desc;
uint32_t color, type;
dice speed, dam, hp, dodge, def, val, weight, attr;
object_description m;
int count;
read_name = read_color = read_desc =
read_speed = read_dam = read_hp = read_attr =
read_type = read_dodge = read_def = read_val =
read_weight = false;
if (*lookahead != "BEGIN") {
std::cerr << "Discovered at " << __FILE__ << ":" << __LINE__ << "\n"
<< "Parse error in object description.\n"
<< "Discarding object." << std::endl;
do {
f >> *lookahead;
} while (*lookahead != "BEGIN" && f.peek() != EOF);
}
示例13: readLine
std::string readLine(std::ifstream &in_)
{
std::string result = "";
while (in_.peek() != '\n' && in_.eof() == false)
{
result += in_.get();
}
in_.get();
return result;
}
示例14: loadNextKeyFrame
int loadNextKeyFrame(int val){ //val = 2 : initial load (2 key frames) ; val = 1 subsequent loads
for ( int i=0;i<34;i++){
curr_angles[i] = next_angles[i];
}
curr_lid_angle = next_lid_angle;
keyFileIn.peek();
if (keyFileIn.good()){
keyFileIn >> l1 >> l2 >> next_lid_angle;
for ( int i=0;i<34;i++){
keyFileIn >> next_angles[i] ;
}
while(keyFileIn.get() != '\n');
keyFileIn.peek();
if(val == 1)
return 0;
}
示例15: ReadRegions
Regions RegionFileLoader::ReadRegions(std::ifstream& f)
{
Regions regions;
std::vector<Double_t> vec;
Char_t next_char;
std::stringstream ss;
Double_t sa;
std::string aline;
while (1)
{
f >> std::ws;
next_char = f.peek();
// check to see if the next is a number,
// if so, this function is done break
if ( ! IsNumber(next_char) )
{
break;
}
std::getline(f,aline);
ss.clear(); ss.str("");
vec.clear();
ss << aline;
ss >> sa;
while(!ss.fail())
{
vec.push_back(sa);
ss >> sa;
}
// std::cout << vec.size() << std::endl;
if (vec.size() == 8)
{
Region region;
region.grid_xlow = vec[0];
region.cntr_xlow = vec[1];
region.grid_xhigh = vec[2];
region.cntr_xhigh = vec[3];
region.grid_ylow = vec[4];
region.cntr_ylow = vec[5];
region.grid_yhigh = vec[6];
region.cntr_yhigh = vec[7];
// std::cout << "filling current region" << std::endl;
regions.push_back(region);
}
}
return regions;
}