本文整理汇总了C++中ifstream::rdstate方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::rdstate方法的具体用法?C++ ifstream::rdstate怎么用?C++ ifstream::rdstate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ifstream
的用法示例。
在下文中一共展示了ifstream::rdstate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkStatus
void checkStatus(ifstream &fin)
{
ios::iostate i;
i = fin.rdstate();
if(i & ios::eofbit)
cout << endl << "EOF encountered \n";
else if(i & ios::failbit)
cout << "Non-fatal I/O error \n";
else if(i & ios::badbit)
cout << "Fatal I/O error \n";
}
示例2: key
/**
* Constructor responsible for reading data from the EDF file.
* It reads data from the header and stores key-value pairs in dictionry.
* Also EDF image is read.
*/
edf_reader::edf_reader(ifstream &in){
char buffer[256], value_string[256];
double value;
char a = ' ';
bool is_header = 0;
int dim1, dim2;
//
//read first character from the file
//
in.get(a);
//
// read file until bace closing the header is met
//
while(in.peek()!='}'){
//
//prevention from corrupted bits in file
//
if(in.fail()){
in.clear(in.rdstate() & ~ios::failbit);
in.getline(buffer, 255);
break;
}
//
//check if the header begins
//
if((a=='{') || is_header==1){
//
//set flag if first time in the loop
//
if(!is_header){
in.get(a);
is_header = 1;
}
//
//get key
//
in.getline(buffer, 255,' ');
string key(buffer);
//
//check if key corresponds to float value
//
if(!strcmp(buffer,"Center_1")||!strcmp(buffer,"Center_2")||!strcmp(buffer,"DDummy")||!strcmp(buffer,"Dummy")||!strcmp(buffer,"Offset_2")||!strcmp(buffer,"Psize_1")||!strcmp(buffer,"Psize_2")||!strcmp(buffer,"SampleDistance")||!strcmp(buffer,"SaxsDataVersion")||!strcmp(buffer,"WaveLength")||!strcmp(buffer,"EDF_BinarySize")||!strcmp(buffer,"Image")||!strcmp(buffer, "Offset_1")) {
//
//get value corresponding to key
//
in.getline(buffer, 255, '=');
while(in.peek()==' ')in.ignore(1,'\n');
in >> value;
//
//store pairs key-double value in key_double dictionary
//
key_double.insert(pair<string, double>(key, value));
}
//
//get dimension separately and store in dictionary
//
else if(!strcmp(buffer,"Dim_1")){
in.getline(buffer, 255, '=');
while(in.peek()==' ')in.ignore(1,'\n');
in >> value;
dim1 = (int)value;
(void)dim1; // TODO unused varable - quiet warnings
key_double.insert(pair<string, double>(key, value));
}