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


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

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


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

示例1: HomoAndMicrosateDis

int HomoAndMicrosateDis(int argc, char *argv[]) {
    if (argc == 1) DisUsage();
    for (int i=0; i<argc; i++) {
        std::cout <<argv[i]<<' ';
    }
    Initial_Time();
    std::cout <<"Start at:  "<<Curr_Time()<< std::endl;
    int noptions = dGetOptions(argc, argv);
    // process user defined region
    if (!one_region.empty()) {  
        if (!polyscan.ParseOneRegion(one_region)) {
            std::cerr<<"fatal error: Please give correct defined region format (-r) \n";
            exit(1);
        }
        polyscan.ifUserDefinedRegion = true;
    } else {
        polyscan.ifUserDefinedRegion = false;
    }
    // reading bed file if is exist
    finB.open(bedFile.c_str());
    if (finB) {
        std::cout << "loading bed regions ..." << std::endl;
        polyscan.LoadBeds(finB);
        polyscan.BedFilterorNot();
    }
    // check bam list file
    finM.open(bamListFile.c_str());
    if (!finM) {
        std::cerr<<"fatal error: failed to open bam list file\n";
        exit(1);
    }
    std::cout << "loading bam list ..." << std::endl;
    polyscan.LoadBams(finM);
    // check homo/microsate file
    finH.open(homoFile.c_str());
    if (!finH) {
        std::cerr<<"fatal error: failed to open homopolymer and microsatellites file\n";
        exit(1);
    }
    std::cout << "loading homopolymer and microsatellite sites ..." << std::endl;
    polyscan.LoadHomosAndMicrosates(finH);
    finH.close();
    //polyscan.TestHomos();
    polyscan.SplitWindows();
    //polyscan.TestWindows();
    std::cout << "\nTotal loading windows:  " << polyscan.totalWindowsNum << " \n\n";
    std::cout << "\nTotal loading homopolymer and microsatellites:  " << polyscan.totalHomosites << " \n\n";
    // pour out distribution
    foutD.open( disFile.c_str() );
    if (!foutD) {
        std::cerr <<"failed to open file: "<<disFile<< std::endl;
        exit(1);
    }
    polyscan.GetHomoDistribution(foutD);
    foutD.close();
    std::cout << "\nTotal time consumed:  " << Cal_AllTime() << " secs\n\n";

    return 0;
}
开发者ID:Beifang,项目名称:polyscape,代码行数:59,代码来源:distribution.cpp

示例2: readFile

	// Read edgelist input file
	inline void readFile(char* filePath, nodeCollection* ncp){
		inputFileStream1.open(filePath);
			std::string line;
			std::string x, y, del;
			int maxValue, a, b;
			char oneLine[256];
			maxValue = 0;

			//To find max Value (to make dynamic array)
			if(inputFileStream1.is_open()){
				int lineNumber = 0;
				while(getline(inputFileStream1, line)){
					strcpy(oneLine,line.c_str());
					del = strtok(oneLine,"\t ");
					x = del;
					y = strtok(NULL,"\t ");
					lineNumber++;
					a = atoi(x.c_str());
					b = atoi(y.c_str());
					
					if ( a > b){
						if(a > maxValue){
							maxValue = a;}
					}
					else{
						if(b > maxValue){
							maxValue = b;}
					}
				}
			}
			else{
				std::cout<<"Error Occured!"<<std::endl;
			}

			//ncp->setAdjMat(maxValue);	//Make matrix
			ncp->setDegMat(maxValue);	//Make degMatrix
			inputFileStream1.seekg(0, inputFileStream1.beg);		//to read again
			inputFileStream1.close();
			inputFileStream2.open(filePath);
			if(inputFileStream2.is_open()){
				while(getline(inputFileStream2, line)){	
					strcpy(oneLine,line.c_str());
					del = strtok(oneLine,"\t ");
					x = del;
					y = strtok(NULL,"\t ");
					a = atoi(x.c_str());
					b = atoi(y.c_str());
					ncp->putNode(a, b);
					ncp->putNode(b, a);
					}
			}
			else{
				std::cout<<"Error Occured!"<<std::endl;
			}
			std::cout<<"####  FILE READ & SETUP FINISHED####"<<std::endl;
			inputFileStream2.close();
			
	}
开发者ID:kujungmul,项目名称:BlackHole,代码行数:59,代码来源:edgeReader.hpp

示例3: init_sim

void init_sim(int argc, char **argv) {
	topology_file.open(argv[1], std::ifstream::in);
	messages_file.open(argv[2], std::ifstream::in);
	events_file.open(argv[3], std::ifstream::in);

	topology_file >> node_ct;
	messages_file >> msg_ct;
	events_file >> time_ct;
	events_file >> event_ct;

	routers.clear();

	//creem obiectele de tip Router
	for(int i = 0; i < node_ct; ++i) routers.push_back( Router(i, node_ct) );

	int r1, cost, r2;
	while( (topology_file >> r1 >> cost >> r2) ) {
		//anuntam routerele despre vecinii lor directi
		routers[r1].add_nbrh(r2, cost);
		routers[r2].add_nbrh(r1, cost);
	} 

	//std::cout << "  [init_sim] sau initilizat " << routers.size() << " routere . . .\n";

	//incepem flodarea retelei cu mesaje despre vecini
	char nbrh_msg[LEN];

	for(unsigned int i = 0; i < routers.size(); ++i) {
		routers[i].table.set_node_no(node_ct);
		routers[i].topology.set_node_no(node_ct);
		routers[i].known_tags.clear();
	}

	for(unsigned int i = 0; i < routers.size(); ++i) {
		make_null(nbrh_msg, LEN);

		//fiecarui mesaj din prima parte a algoritmului de flodare
		//ii setam tagul egal cu -id-ul routerului care la pornit
		//in acest fel mesajele ce contin toti vecini vor avea tagul un numar negativ sau 0
		sprintf(nbrh_msg, "%d ", -i);  //tag == -i

		sprintf(nbrh_msg + strlen(nbrh_msg), "%d %d ", i, routers[i].nbrh.size());

		for(unsigned int j = 0; j < routers[i].nbrh.size(); ++j) {
			sprintf(nbrh_msg + strlen(nbrh_msg), "%d %d ", routers[i].nbrh[j], routers[i].get_nbrh_cost(routers[i].nbrh[j]));
		} 

		for(unsigned int j = 0; j < routers[i].nbrh.size(); ++j) {
			//cout << "----------------de la " << i << " la " << j << " sa trimis " << nbrh_msg << "\n";
			endpoint[i].send_msg(&endpoint[routers[i].nbrh[j]], nbrh_msg, strlen(nbrh_msg), NULL);
		}

	}  


}
开发者ID:vasiletoncu,项目名称:TemePC-2015,代码行数:56,代码来源:sim.cpp

示例4: OpenFile

std::string MiscUtil::OpenFile(std::string name, std::ifstream& f)
{
#ifndef ABS_TOP_SRCDIR
    #error ABS_TOP_SRCDIR not defined!
#endif
#ifndef DATADIR
    #error ABS_TOP_SRCDIR not defined!
#endif
    std::string programDirFile;
    std::string absFile;
    std::string dataFile;
    # if defined(BOOST_FILESYSTEM_VERSION)
        BenzeneAssert (BOOST_FILESYSTEM_VERSION == 2 || BOOST_FILESYSTEM_VERSION == 3);
    #endif
    {
        path p = programDir / name;
        p.normalize();
        #if (defined (BOOST_FILESYSTEM_VERSION) && (BOOST_FILESYSTEM_VERSION == 3))
            programDirFile = p.string();
        #else
            programDirFile = p.native_file_string();
        #endif
        f.open(programDirFile.c_str());
        if (f.is_open())
            return programDirFile;
    }
    {
        path p = boost::filesystem::path(ABS_TOP_SRCDIR) / "share" / name;
        p.normalize();
        #if (defined (BOOST_FILESYSTEM_VERSION) && (BOOST_FILESYSTEM_VERSION == 3))
            absFile = p.string();
        #else
            absFile = p.native_file_string();
        #endif
        f.open(absFile.c_str());
        if (f.is_open())
            return absFile;
    }
    {
        path p = boost::filesystem::path(DATADIR) / name;
        p.normalize();
        #if (defined (BOOST_FILESYSTEM_VERSION) && (BOOST_FILESYSTEM_VERSION == 3))
            dataFile = p.string();
        #else
            dataFile = p.native_file_string();
        #endif
        f.open(dataFile.c_str());
        if (f.is_open())
            return dataFile;
    }
    throw BenzeneException() << "Could not find '" << name << "'. Tried \n"
                             << "\t'" << programDirFile << "' and\n"
                             << "\t'" << absFile << "' and\n"
                             << "\t'" << dataFile << "'.";
}
开发者ID:kenjyoung,项目名称:benzene-vanilla,代码行数:55,代码来源:Misc.cpp

示例5: openTextFile

    static void openTextFile(const std::string& filepath, std::ifstream& file){
        
#ifdef _WIN32
        // WIN32 will create the wrong file names if we don't first convert them to UTF-16.
        std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
        std::wstring wide_path = converter.from_bytes(filepath);
        file.open(wide_path, std::ios::in);
#else
        file.open(filepath, std::ios::in);
#endif
    }
开发者ID:Jinwei1,项目名称:AirSim,代码行数:11,代码来源:FileSystem.hpp

示例6: ResetFiles

 /**
  * This method closes and reopens files so that another CompareFiles() command can be run on the same object.
  */
 void ResetFiles()
 {
     if (!mCalledCollectively || PetscTools::AmMaster())
     {
         // We want to reset the files to allow this method to be called again, with different tolerances for instance.
         mpFile1->close();
         mpFile2->close();
         mpFile1->open(mFilename1.c_str());
         mpFile2->open(mFilename2.c_str());
         mLineNum = 1u;
     }
 }
开发者ID:Chaste,项目名称:Chaste,代码行数:15,代码来源:AbstractFileComparison.hpp

示例7: index_path

	em_blob(const char *path) : completed(0), path_(path) {
		try {
			data.open(path, std::ios_base::in | std::ios_base::binary);
			std::string index_path(path);
			index_path += ".index";
			index.open(index_path.c_str(), std::ios_base::in | std::ios_base::binary);
		} catch (...) {
			data.close();
			index.close();

			throw;
		}
	}
开发者ID:torkve,项目名称:eblob,代码行数:13,代码来源:merge.cpp

示例8: openASCIIFiles

bool NodePartitionedMeshReader::openASCIIFiles(std::string const& file_name_base,
    std::ifstream& is_cfg, std::ifstream& is_node, std::ifstream& is_elem) const
{
    const std::string fname_header = file_name_base +  "_partitioned_";
    const std::string fname_num_p_ext = std::to_string(_mpi_comm_size) + ".msh";

    {   // Configuration.
        std::string const filename = fname_header + "cfg" + fname_num_p_ext;
        is_cfg.open(filename);

        if( !is_cfg.good() )
        {
            ERR("Error opening file %s for input.", filename.c_str());
            return false;
        }

        std::string tmp_line;
        std::getline(is_cfg, tmp_line);
        int num_parts;
        is_cfg >> num_parts >> std::ws;

        if(num_parts != _mpi_comm_size)
        {
            ERR("Aborting computation because of number of cores"
                "/ subdomains mismatch.");
            return false;
        }
    }

    {   // Nodes.
        std::string const filename = fname_header + "nodes_" + fname_num_p_ext;
        is_node.open(filename);
        if( !is_node.good() )
        {
            ERR("Error opening file %s for input.", filename.c_str());
            return false;
        }
    }

    {   // Elements.
        std::string const filename = fname_header + "elems_" + fname_num_p_ext;
        is_elem.open(filename);
        if( !is_elem.good() )
        {
            ERR("Error opening file %s for input.", filename.c_str());
            return false;
        }
    }

    return true;
}
开发者ID:Doublle,项目名称:ogs,代码行数:51,代码来源:NodePartitionedMeshReader.cpp

示例9: open_ifstream

 void open_ifstream(std::ifstream& stream,const std::string& path,bool binary)
 {
   std::ifstream::openmode mode=std::ifstream::in;
   if(binary)
     mode|=std::ifstream::binary;
   #ifdef WIN32
   std::wstring wpath;
   utf8::utf8to16(path.begin(),path.end(),std::back_inserter(wpath));
   stream.open(wpath.c_str(),mode);
   #else
   stream.open(path.c_str(),mode);
   #endif
   if(!stream.is_open())
     throw open_error(path);
 }
开发者ID:AlexShadow,项目名称:RHVoice,代码行数:15,代码来源:io.cpp

示例10: openInputFile

void openInputFile(std::ifstream& s, std::string path){
  s.open(path);
  if(s.fail()){
    std::cerr << "Failure opening file \"" << path << "\" for input." << std::endl;
    exit(0);
  }
}
开发者ID:bfisch02,项目名称:csax_cpp,代码行数:7,代码来源:io.cpp

示例11: _ctor

   void _ctor(ev4::string<>& _FileName, std::size_t _BufferSize)
   {
      _m_buffer = new char[_BufferSize];
      _m_filename = new ev4::string<>(_FileName);

      _m_file.open(_FileName.c_str());
   }
开发者ID:jashook,项目名称:ev6,代码行数:7,代码来源:parser.hpp

示例12: fOpen

/*Name: fOpen
//Purpose: Opens file with given filename
//Parameters: ifstream object, string filename, bool fail bit
//Returns: null
*/
void fOpen(std::ifstream& fin, string filename, bool& fail){
	fin.open(filename.c_str());
	if(!fin.is_open()){
		fail = 1;
		cerr << "File failed to open";
	}
}
开发者ID:jbu92,项目名称:schoolstuff,代码行数:12,代码来源:Project1.cpp

示例13: open

 void open( const std::string& anchorFile ) {
   _in.close();
   _in.clear();
   _in.open( anchorFile.c_str() );
   _buffer.clear();
   _readDocumentHeader();
 }
开发者ID:busjaeger,项目名称:cs410sp12,代码行数:7,代码来源:AnchorTextAnnotator.hpp

示例14: main

int main(int argc, const char* argv[]){
	//Check and parse the command line arguments
	if(argc<MIN_ARGC || argc>MAX_ARGC){
		wrong_usage_msg(argc-1);
	}
	
	//Leaving room for more future command line options
	std::string filename;
	bool inFileSupplied=false;
	for(int i=1;i<argc;i++){
		if(file_exists(argv[i])){
			filename=argv[i];
			inFileSupplied=true;
		}
		else{
			invalid_arg_msg(argv[i]);
		}
	}
	
	if(!inFileSupplied)
		fatal("[ERROR] Input file not defined: "+filename+"\n");
	
	inFile.open(filename);
	
	//Parse the input file into a list of commands
	parse();
	//Execute it!
	execute();
	
	return 0;
}
开发者ID:WeirdLionStudios,项目名称:vvm,代码行数:31,代码来源:main.cpp

示例15: read_file

    bool InpNativeInfo::read_file(const std::string& file_name)
    {
        if(already_read)
            std::cout << "Warning: trying to substitute ninfo for already initiated object." 
                      << std::endl;
        already_read = true;

        if(inpfile.is_open())
        {
            std::cout << "Warning: trying to re-open file named " << file_name
                      << std::endl;
        }
        inpfile.open(file_name);
        bool read(false);
        
        while(!inpfile.eof())
        {
            std::string line;
            std::getline(inpfile, line);

            if(line.empty()) continue;
            if(line[0] == '\x2a') continue;

            if(eq_ignorecase(line.substr(0,20), "<<<< native_info_sim"))
            {
                read = true;
                std::string temp(line, 20);
                simN = std::stoi(temp);
                read_block(inpfile);
            }
        }
        return read;
    }
开发者ID:ToruNiina,项目名称:NinfoTools,代码行数:33,代码来源:InpNativeInfo.hpp


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