当前位置: 首页>>代码示例>>C++>>正文


C++ ifstream::rdstate方法代码示例

本文整理汇总了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";
}
开发者ID:niravchotai,项目名称:cpp,代码行数:15,代码来源:fileStatus.cpp

示例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));	            
	    }
开发者ID:Acidburn0zzz,项目名称:code,代码行数:73,代码来源:edf_reader.cpp


注:本文中的ifstream::rdstate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。