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


C++ fstream::is_open方法代码示例

本文整理汇总了C++中std::fstream::is_open方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::is_open方法的具体用法?C++ fstream::is_open怎么用?C++ fstream::is_open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::fstream的用法示例。


在下文中一共展示了fstream::is_open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: encryptData

bool XorEncryptor::encryptData(std::fstream &original, std::fstream &result)
{
	if (!original.is_open() || !result.is_open())
	{
		return false;
	}

	original.seekg(0, std::ios::beg);
	result.seekp(0, std::ios::beg);

	char c = 0;
	unsigned i = 0;
	while (original.good())
	{
		original.read(&c, 1);
		c ^= password[i];
		if(original.gcount() > 0)
		{
			result.write(&c, 1);
		}

		if (++i == passSize)
		{
			i = 0;
		}
	}

	original.seekg(0, std::ios::beg);
	result.seekg(0, std::ios::beg);
	result.flush();

	return true;
}
开发者ID:Yashchuk,项目名称:GL-Base-camp,代码行数:33,代码来源:XorEncryptor.cpp

示例2: NMPRK_StartDebugLogging

NMPRKC_API nmprk_status_t NMPRK_StartDebugLogging(
	const char *filename)
{
	char dateStr[MAX_DATE_STR_LEN];
	char timeStr[MAX_DATE_STR_LEN];

	if(si_fsDebugLog.is_open() == true)
		return NMPRK_FAILURE;

	try
	{
		si_debugModule = SI_DEBUG_MODULE_ALL;
		si_debugLevel = SI_DEBUG_LEVEL_ALL;
		si_fsDebugLog.open(filename, std::fstream::out | std::fstream::app);
		if(si_fsDebugLog.is_open() != true)
			return NMPRK_FAILURE;
	}
	catch (...)
	{
		return NMPRK_FAILURE;
	}

#if defined WIN32
	_strdate_s(dateStr, MAX_DATE_STR_LEN);
	_strtime_s(timeStr, MAX_DATE_STR_LEN);
#else
	time_t mytime = time(NULL);
	strftime(dateStr, 9, "%D", localtime(&mytime));
	strftime(timeStr, 9, "%T", localtime(&mytime));
#endif
		
	SI_DEBUG_INFO(SI_THIS_MODULE, "Debug Logging Started: %s %s", dateStr, timeStr);

	return NMPRK_SUCCESS;
}
开发者ID:01org,项目名称:NMPRK,代码行数:35,代码来源:nmprkC.cpp

示例3: verifiedOC

// Ensures the file is opened/closed properly and retries 5 times.
// if choice is false, the file is closed and if it is 1, the file is opened.
bool verifiedOC ( std::fstream& file, std::string fileDir, bool choice, std::ios::openmode io ) {
    unsigned int i = 0; // Declaring a counter variable.
    
    // Choice determines if we are opening or closing the file. (True to open, False to close)
    if ( choice ) {
        do {
            file.open ( fileDir.c_str(), io );  // Open file as user selection.
            if ( file.is_open() ) {
                return true;
            } else {
                // Prints that the attempt to change the file state has failed.
                std::cout << "The file " << fileDir.c_str() << " failed to open... Retrying " << ++i << "\n";
            }
        
            // Will exit the loop after the the number of attempts FILE_OPEN_RETRIES specifies.
            if ( i >= FILE_OPEN_RETRIES ) {
                std::cout << "The file " << fileDir.c_str() << " failed to change open." << std::endl;
                return false;
            }
        } while ( !file.is_open() );
    } else {
        file.close();
    }
    
    return true;
}
开发者ID:Denakee,项目名称:CS10A,代码行数:28,代码来源:deck.cpp

示例4: rawOpen

bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
{
    std::ios_base::openmode fmode = std::fstream::binary;
    if (mode == File::Write) {
        fmode |= (std::fstream::out | std::fstream::trunc);
        createCache(SNAPPY_CHUNK_SIZE);
    } else if (mode == File::Read) {
        fmode |= std::fstream::in;
    }

    m_stream.open(filename.c_str(), fmode);

    //read in the initial buffer if we're reading
    if (m_stream.is_open() && mode == File::Read) {
        m_stream.seekg(0, std::ios::end);
        m_endPos = m_stream.tellg();
        m_stream.seekg(0, std::ios::beg);

        // read the snappy file identifier
        unsigned char byte1, byte2;
        m_stream >> byte1;
        m_stream >> byte2;
        assert(byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2);

        flushReadCache();
    } else if (m_stream.is_open() && mode == File::Write) {
开发者ID:Hsaniva,项目名称:apitrace,代码行数:26,代码来源:trace_file_snappy.cpp

示例5: load

bool ClassLabelChangeFilter::load( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "load(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" ){
        errorLog << "load(fstream &file) - Invalid file format!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "NumInputDimensions:" ){
        errorLog << "load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
        return false;
    }
    file >> numInputDimensions;
    
    //Load the number of output dimensions
    file >> word;
    if( word != "NumOutputDimensions:" ){
        errorLog << "load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
        return false;
    }
    file >> numOutputDimensions;
    
    //Init the classLabelTimeoutFilter module to ensure everything is initialized correctly
    return init();
}
开发者ID:nickgillian,项目名称:grt,代码行数:35,代码来源:ClassLabelChangeFilter.cpp

示例6: saveModelToFile

bool TimeDomainFeatures::saveModelToFile( std::fstream &file ) const{
    
    if( !file.is_open() ){
        errorLog << "saveModelToFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    //Write the file header
    file << "GRT_TIME_DOMAIN_FEATURES_FILE_V1.0" << std::endl;	
    
    //Save the base settings to the file
    if( !saveFeatureExtractionSettingsToFile( file ) ){
        errorLog << "saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
        return false;
    }
    
    //Write the time domain settings to the file
    file << "BufferLength: " << bufferLength << std::endl;
    file << "NumFrames: " << numFrames << std::endl;
    file << "OffsetInput: " << offsetInput << std::endl;
    file << "UseMean: " << useMean << std::endl;
    file << "UseStdDev: " << useStdDev << std::endl;
    file << "UseEuclideanNorm: " << useEuclideanNorm << std::endl;
    file << "UseRMS: " << useRMS << std::endl;
    
    return true;
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:27,代码来源:TimeDomainFeatures.cpp

示例7: save

bool RBMQuantizer::save( std::fstream &file ) const{
    
    if( !file.is_open() ){
        errorLog << "save(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    //Write the header
    file << "RBM_QUANTIZER_FILE_V1.0" << std::endl;
    
    //Save the base feature extraction settings to the file
    if( !saveFeatureExtractionSettingsToFile( file ) ){
        errorLog << "saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
        return false;
    }
    
    file << "QuantizerTrained: " << trained << std::endl;
    file << "NumClusters: " << numClusters << std::endl;
    
    if( trained ){
        if( !rbm.save( file ) ){
            errorLog << "save(fstream &file) - Failed to save RBM settings to file!" << std::endl;
            return false;
        }
    }
    
    return true;
}
开发者ID:sgrignard,项目名称:grt,代码行数:28,代码来源:RBMQuantizer.cpp

示例8: loadPostProcessingSettingsFromFile

bool PostProcessing::loadPostProcessingSettingsFromFile(std::fstream &file){
    
    if( !file.is_open() ){
        errorLog << "loadPostProcessingSettingsFromFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    //Try and load the base settings from the file
    if( !MLBase::loadBaseSettingsFromFile( file ) ){
        return false;
    }
    
    std::string word;
    
    //Load if the filter has been initialized
    file >> word;
    if( word != "Initialized:" ){
        errorLog << "loadPostProcessingSettingsFromFile(fstream &file) - Failed to read Initialized header!" << std::endl;
        clear();
        return false;
    }
    file >> initialized;
    
    //If the module has been initalized then call the init function to setup the processed data vector
    if( initialized ){
        return init();
    }
    
    return true;
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:30,代码来源:PostProcessing.cpp

示例9: saveModelToFile

bool LinearRegression::saveModelToFile( std::fstream &file ) const{
    
    if(!file.is_open())
	{
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
		return false;
	}
    
	//Write the header info
    file<<"GRT_LINEAR_REGRESSION_MODEL_FILE_V2.0\n";
    
    //Write the regressifier settings to the file
    if( !Regressifier::saveBaseSettingsToFile(file) ){
        errorLog <<"saveModelToFile(fstream &file) - Failed to save Regressifier base settings to file!" << std::endl;
		return false;
    }
    
    if( trained ){
        file << "Weights: ";
        file << w0;
        for(UINT j=0; j<numInputDimensions; j++){
            file << " " << w[j];
        }
        file << std::endl;
    }
    
    return true;
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:28,代码来源:LinearRegression.cpp

示例10: read_matrix_size

void read_matrix_size(std::fstream& f, std::size_t & sz1, std::size_t & sz2)
{
  if(!f.is_open())
    throw std::invalid_argument("File is not opened");

  f >> sz1 >> sz2;
}
开发者ID:YannCobigo,项目名称:viennacl-dev,代码行数:7,代码来源:svd.cpp

示例11: main

int main(int argc, char *argv[]) {
	//Initialize symbol table code. Pin does not read symbols unless this is called
	PIN_InitSymbols();

	//initialize Pin system
	if(PIN_Init(argc,argv)) {
		return Usage();
	}

    string filename = KnobOutputFile.Value();

    //file to record all instructions
    #ifdef LOG_ASSEM
     //TraceFile.open(filename, ios::out);
     AxOpenFile(TraceFile, filename);
     if (TraceFile.is_open()) {
        PRINT_SCN(filename << " : Start to make trace at instruction #" << InsCount);
     } else {
        PRINT_SCN("cannot open");
        return -1;
     }
    #endif
    //file to record all memory accesses
    MemFile.open("mem.txt", ios::out);

	//add a function used to instrument at instruction granularity 
	INS_AddInstrumentFunction(Instruction, 0);
	//call 'Fini' immediately before the application exits
	PIN_AddFiniFunction(Fini, 0);

	//starts executing the application
	PIN_StartProgram();

	return 0;
}
开发者ID:cinwell,项目名称:pin_assem,代码行数:35,代码来源:pinAssem.cpp

示例12: load

bool TimeseriesBuffer::load( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "load(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_TIMESERIES_BUFFER_FILE_V1.0" ){
        errorLog << "load(fstream &file) - Invalid file format!" << std::endl;
        return false;
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "BufferSize:" ){
        errorLog << "load(fstream &file) - Failed to read BufferSize header!" << std::endl;
        return false;
    }
    file >> bufferSize;
    
    //Init the TimeseriesBuffer module to ensure everything is initialized correctly
    return init(bufferSize,numInputDimensions);
}
开发者ID:nickgillian,项目名称:grt,代码行数:32,代码来源:TimeseriesBuffer.cpp

示例13: loadModelFromFile

bool FFT::loadModelFromFile( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_FFT_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
        return false;     
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "HopSize:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read HopSize header!" << std::endl;
        return false;     
    }
    file >> hopSize;
    
    file >> word;
    if( word != "FftWindowSize:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read FftWindowSize header!" << std::endl;
        return false;     
    }
    file >> fftWindowSize;
    
    file >> word;
    if( word != "FftWindowFunction:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read FftWindowFunction header!" << std::endl;
        return false;     
    }
    file >> fftWindowFunction;
    
    file >> word;
    if( word != "ComputeMagnitude:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputeMagnitude header!" << std::endl;
        return false;     
    }
    file >> computeMagnitude;
    
    file >> word;
    if( word != "ComputePhase:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputePhase header!" << std::endl;
        return false;     
    }
    file >> computePhase;
    
    //Init the FFT module to ensure everything is initialized correctly
    return init(fftWindowSize,hopSize,numInputDimensions,fftWindowFunction,computeMagnitude,computePhase);
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:60,代码来源:FFT.cpp

示例14: loadParametersFromFile

bool DecisionTreeClusterNode::loadParametersFromFile( std::fstream &file ){

    if(!file.is_open())
    {
        errorLog << __GRT_LOG__ << " File is not open!" << std::endl;
        return false;
    }

    //Load the DecisionTreeNode parameters
    if( !DecisionTreeNode::loadParametersFromFile( file ) ){
        errorLog << __GRT_LOG__ << " Failed to load DecisionTreeNode parameters from file!" << std::endl;
        return false;
    }

    std::string word;
    //Load the custom DecisionTreeThresholdNode Parameters
    file >> word;
    if( word != "FeatureIndex:" ){
        errorLog << __GRT_LOG__ << " Failed to find FeatureIndex header!" << std::endl;
        return false;
    }
    file >> featureIndex;

    file >> word;
    if( word != "Threshold:" ){
        errorLog << __GRT_LOG__ << " Failed to find Threshold header!" << std::endl;
        return false;
    }
    file >> threshold;

    return true;
}
开发者ID:nickgillian,项目名称:grt,代码行数:32,代码来源:DecisionTreeClusterNode.cpp

示例15: saveModelToFile

bool FFT::saveModelToFile( std::fstream &file ) const{
    
    if( !file.is_open() ){
        errorLog << "saveModelToFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    //Write the file header
    file << "GRT_FFT_FILE_V1.0" << std::endl;
    
    //Save the base settings to the file
    if( !saveFeatureExtractionSettingsToFile( file ) ){
        errorLog << "saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
        return false;
    }
    
    //Write the FFT settings
    file << "HopSize: " << hopSize << std::endl;
    file << "FftWindowSize: " << fftWindowSize << std::endl;
    file << "FftWindowFunction: " << fftWindowFunction << std::endl;
    file << "ComputeMagnitude: " << computeMagnitude << std::endl;
    file << "ComputePhase: " << computePhase << std::endl;
    
    return true;
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:25,代码来源:FFT.cpp


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