• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ifstream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getline

bool CLevel::LoadVersion1( ifstream& File ) {

    bool StopReadingFile = false;
    filebuf *pbuf = File.rdbuf();
    
    // go to the beginning
    pbuf->pubseekpos (0,ios::in);

    // For each line of characters to read
    for (int y = 0 ; y < ARENA_HEIGHT ; y++)
    {
        // Buffer where we'll store one line of characters. We'll read the two EOL characters as well.
        string Line;
        int ReadBytes;
    
        // Read one line of characters (including the EOL chars)
        if (File.good())
        {
            getline( File, Line );
            ReadBytes = Line.size();
        }
        else
        {
            ReadBytes = 0;
        }

        // Check if all the characters were read
        if (ReadBytes < ARENA_WIDTH)
        {
            // Log there is a problem
            theLog.WriteLine ("Options         => !!! Level file is incorrect (Line: %d, Length: %d).", y+1, ReadBytes);
        
            // Close the level file
            File.close();

            // Stop loading levels
            StopReadingFile = true;
            break;
        }

        // For each character representing a block in this line
        for (int x = 0 ; x < ARENA_WIDTH ; x++)
        {
            // According to the character value, store the corresponding block type in the current position and level
            switch(Line.c_str()[x])
            {
                case '*' : m_ArenaData[x][y] = BLOCKTYPE_HARDWALL;    break;
                case '-' : m_ArenaData[x][y] = BLOCKTYPE_RANDOM;      break;
                case ' ' : m_ArenaData[x][y] = BLOCKTYPE_FREE;        break;
                case '1' : m_ArenaData[x][y] = BLOCKTYPE_WHITEBOMBER; break;
                case '2' : m_ArenaData[x][y] = BLOCKTYPE_BLACKBOMBER; break;
                case '3' : m_ArenaData[x][y] = BLOCKTYPE_REDBOMBER;   break;
                case '4' : m_ArenaData[x][y] = BLOCKTYPE_BLUEBOMBER;  break;
                case '5' : m_ArenaData[x][y] = BLOCKTYPE_GREENBOMBER; break;
                case 'R' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_RIGHT; break;
                case 'D' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_DOWN;  break;
                case 'L' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_LEFT;  break;
                case 'U' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_UP;    break;
                default  : 
                {
                    // Log there is a problem
                    theLog.WriteLine ("Options         => !!! Level file is incorrect (unknown character %c).", Line[x]);
                
                    // Close the level file
                    File.close();

                    // Stop loading levels
                    StopReadingFile = true;
                    break;
                }
            }
        }

        // If there was a problem
        if (StopReadingFile)
        {
            // Stop reading this level file
            break;
        }
    }

    m_NumberOfItemsInWalls[ITEM_BOMB] = INITIAL_ITEMBOMB;
    m_NumberOfItemsInWalls[ITEM_FLAME] = INITIAL_ITEMFLAME;
    m_NumberOfItemsInWalls[ITEM_KICK] = INITIAL_ITEMKICK;
    m_NumberOfItemsInWalls[ITEM_ROLLER] = INITIAL_ITEMROLLER;
    m_NumberOfItemsInWalls[ITEM_SKULL] = INITIAL_ITEMSKULL;
    m_NumberOfItemsInWalls[ITEM_THROW] = INITIAL_ITEMTHROW;
    m_NumberOfItemsInWalls[ITEM_PUNCH] = INITIAL_ITEMPUNCH;
	m_NumberOfItemsInWalls[ITEM_REMOTE] = INITIAL_ITEMREMOTE;

    m_InitialBomberSkills[ BOMBERSKILL_FLAME ] = INITIAL_FLAMESIZE;
    m_InitialBomberSkills[ BOMBERSKILL_BOMBS ] = INITIAL_BOMBS;
    m_InitialBomberSkills[ BOMBERSKILL_BOMBITEMS ] = 0;
    m_InitialBomberSkills[ BOMBERSKILL_FLAMEITEMS ] = 0;
    m_InitialBomberSkills[ BOMBERSKILL_ROLLERITEMS ] = 0;
    m_InitialBomberSkills[ BOMBERSKILL_KICKITEMS ] = 0;
    m_InitialBomberSkills[ BOMBERSKILL_THROWITEMS ] = 0;
    m_InitialBomberSkills[ BOMBERSKILL_PUNCHITEMS ] = 0;
	m_InitialBomberSkills[ BOMBERSKILL_REMOTEITEMS ] = 0;
    
//.........这里部分代码省略.........
开发者ID:Bombermaaan-R,项目名称:bombermaaan-r,代码行数:101,代码来源:CLevel.cpp


示例2: operator

	void operator ()(ifstream& f)
	{	
		if (!f.is_open()) {
			throw contract_exception();
		}
	}
开发者ID:dlyfar,项目名称:variadic-templates-function-contracts,代码行数:6,代码来源:variadic.cpp


示例3: parsefile

void parsefile(ifstream &file, ifstream &file2, ifstream &file3,ifstream &file4, ifstream &file5){


    for (int i=0; i<600; i++) {
        for(int j=0; j<600; j++){
            zbuffer[i][j] = std::numeric_limits<int>::min();
        }

    }
    double Ax;
    double Ay;
    double Az;
    double Atexturex;
    double Atexturey;
    double Avecteurx;
    double Avecteury;
    double Avecteurz;

    double Bx;
    double By;
    double Bz;
    double Btexturex;
    double Btexturey;
    double Bvecteurx;
    double Bvecteury;
    double Bvecteurz;


    double Cx;
    double Cy;
    double Cz;
    double Ctexturex;
    double Ctexturey;
    double Cvecteurx;
    double Cvecteury;
    double Cvecteurz;

    file.open("african_head.obj");
    file2.open("african_head.obj");
    file3.open("african_head.obj");
    file4.open("african_head.obj");

    getLineCoordV(file);
    getLineCoordVt(file3);
    getLineCoordVn(file4);


    int nombre1;
    int nombre2;
    int nombre3;
    int nombre1vt;
    int nombre2vt;
    int nombre3vt;
    int nombre1vn;
    int nombre2vn;
    int nombre3vn;
    std::string myString;
    while (!file2.eof())
    {

      getline(file2, myString);
	  if ((myString[0] == 'f') && (myString[1] == ' ')) {
        myString.erase(myString.begin(),myString.begin()+2);
		  int i = 0;
		  while (myString[i] == ' ') {
			  i++;
		  }
		  while (myString[i] != '/') {
			  char c = myString[i];

    // PREMIER SOMMET
			  sommet1.push_back(c);
			  i++;
		  }
		  i++;
		  while (myString[i] != '/') {

              char c = myString[i];

    // Texture PREMIER SOMMET
			  couleursommet1.push_back(c);
			  i++;


		  }
		  i++;
		  while (myString[i] != ' ') {

              char c = myString[i];

    // Vecteur PREMIER SOMMET
			  vecteursommet1.push_back(c);
			  i++;

		  }
		  while (myString[i] == ' ') {
			  i++;
		  }
		  while (myString[i] != '/') {
			  char c = myString[i];
//.........这里部分代码省略.........
开发者ID:BallyB,项目名称:Infographie,代码行数:101,代码来源:main.cpp


示例4: while

/*************************************************************************************************
map<string, int> Bayesian::parseTaxMap(string newTax) {
	try{
	
		map<string, int> parsed;
		
		newTax = newTax.substr(0, newTax.length()-1);  //get rid of last ';'
	
		//parse taxonomy
		string individual;
		while (newTax.find_first_of(';') != -1) {
			individual = newTax.substr(0,newTax.find_first_of(';'));
			newTax = newTax.substr(newTax.find_first_of(';')+1, newTax.length());
			parsed[individual] = 1;
		}
		
		//get last one
		parsed[newTax] = 1;

		return parsed;
		
	}
	catch(exception& e) {
		m->errorOut(e, "Bayesian", "parseTax");
		exit(1);
	}
}
**************************************************************************************************/
void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string inNumName) {
	try{
		
		#ifdef USE_MPI
			
			int pid, num, num2, processors;
			vector<unsigned long long> positions;
			vector<unsigned long long> positions2;
			
			MPI_Status status; 
			MPI_File inMPI;
			MPI_File inMPI2;
			MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
			MPI_Comm_size(MPI_COMM_WORLD, &processors);
			int tag = 2001;

			char inFileName[1024];
			strcpy(inFileName, inNumName.c_str());
			
			char inFileName2[1024];
			strcpy(inFileName2, inName.c_str());

			MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
			MPI_File_open(MPI_COMM_WORLD, inFileName2, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI2);  //comm, filename, mode, info, filepointer

			if (pid == 0) {
				positions = m->setFilePosEachLine(inNumName, num);
				positions2 = m->setFilePosEachLine(inName, num2);
				
				for(int i = 1; i < processors; i++) { 
					MPI_Send(&num, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
					MPI_Send(&positions[0], (num+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
					
					MPI_Send(&num2, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
					MPI_Send(&positions2[0], (num2+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
				}

			}else{
				MPI_Recv(&num, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
				positions.resize(num+1);
				MPI_Recv(&positions[0], (num+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
				
				MPI_Recv(&num2, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
				positions2.resize(num2+1);
				MPI_Recv(&positions2[0], (num2+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
			}
			
			//read version
			int length = positions2[1] - positions2[0];
			char* buf5 = new char[length];

			MPI_File_read_at(inMPI2, positions2[0], buf5, length, MPI_CHAR, &status);
			delete buf5;

			//read numKmers
			length = positions2[2] - positions2[1];
			char* buf = new char[length];

			MPI_File_read_at(inMPI2, positions2[1], buf, length, MPI_CHAR, &status);

			string tempBuf = buf;
			if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
			delete buf;

			istringstream iss (tempBuf,istringstream::in);
			iss >> numKmers;  
			
			//initialze probabilities
			wordGenusProb.resize(numKmers);
			
			for (int j = 0; j < wordGenusProb.size(); j++) {	wordGenusProb[j].resize(genusNodes.size());		}
			
//.........这里部分代码省略.........
开发者ID:EdwardMoseley,项目名称:mothur,代码行数:101,代码来源:bayesian.cpp


示例5: while

/*************************************************************************************************
map<string, int> Bayesian::parseTaxMap(string newTax) {
	try{

		map<string, int> parsed;

		newTax = newTax.substr(0, newTax.length()-1);  //get rid of last ';'

		//parse taxonomy
		string individual;
		while (newTax.find_first_of(';') != -1) {
			individual = newTax.substr(0,newTax.find_first_of(';'));
			newTax = newTax.substr(newTax.find_first_of(';')+1, newTax.length());
			parsed[individual] = 1;
		}

		//get last one
		parsed[newTax] = 1;

		return parsed;

	}
	catch(exception& e) {
		m->errorOut(e, "Bayesian", "parseTax");
		exit(1);
	}
}
**************************************************************************************************/
void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string inNumName) {
    try {

        //read version
        string line = m->getline(in);
        m->gobble(in);

        in >> numKmers;
        m->gobble(in);
        //initialze probabilities
        wordGenusProb.resize(numKmers);

        for (int j = 0; j < wordGenusProb.size(); j++) {
            wordGenusProb[j].resize(genusNodes.size());
        }

        int kmer, name, count;
        count = 0;
        vector<int> num;
        num.resize(numKmers);
        float prob;
        vector<float> zeroCountProb;
        zeroCountProb.resize(numKmers);
        for (int j = 0; j < numKmers; j++) {
            diffPair tempDiffPair;
            WordPairDiffArr.push_back(tempDiffPair);
        }

        //read version
        string line2 = m->getline(inNum);
        m->gobble(inNum);
        float probTemp;

        while (inNum) {
            inNum >> zeroCountProb[count] >> num[count] >> probTemp;
            WordPairDiffArr[count].prob = probTemp;
            count++;
            m->gobble(inNum);

        }
        inNum.close();

        while(in) {
            in >> kmer;

            //set them all to zero value
            for (int i = 0; i < genusNodes.size(); i++) {
                wordGenusProb[kmer][i] = log(zeroCountProb[kmer] / (float) (genusTotals[i]+1));
            }

            //get probs for nonzero values
            for (int i = 0; i < num[kmer]; i++) {
                in >> name >> prob;
                wordGenusProb[kmer][name] = prob;
            }

            m->gobble(in);
        }
        in.close();


    }
    catch(exception& e) {
        m->errorOut(e, "Bayesian", "readProbFile");
        exit(1);
    }
}
开发者ID:Cryomics-Lab,项目名称:mothur,代码行数:95,代码来源:bayesian.cpp


示例6: checkReleaseDate

bool Bayesian::checkReleaseDate(ifstream& file1, ifstream& file2, ifstream& file3, ifstream& file4) {
    try {

        bool good = true;

        vector<string> lines;
        lines.push_back(m->getline(file1));
        lines.push_back(m->getline(file2));
        lines.push_back(m->getline(file3));
        lines.push_back(m->getline(file4));

        //before we added this check
        if ((lines[0][0] != '#') || (lines[1][0] != '#') || (lines[2][0] != '#') || (lines[3][0] != '#')) {
            good = false;
        }
        else {
            //rip off #
            for (int i = 0; i < lines.size(); i++) {
                lines[i] = lines[i].substr(1);
            }

            //get mothurs current version
            string version = m->getVersion();

            vector<string> versionVector;
            m->splitAtChar(version, versionVector, '.');

            //check each files version
            for (int i = 0; i < lines.size(); i++) {
                vector<string> linesVector;
                m->splitAtChar(lines[i], linesVector, '.');

                if (versionVector.size() != linesVector.size()) {
                    good = false;
                    break;
                }
                else {
                    for (int j = 0; j < versionVector.size(); j++) {
                        int num1, num2;
                        convert(versionVector[j], num1);
                        convert(linesVector[j], num2);

                        //if mothurs version is newer than this files version, then we want to remake it
                        if (num1 > num2) {
                            good = false;
                            break;
                        }
                    }
                }

                if (!good) {
                    break;
                }
            }
        }

        if (!good) {
            file1.close();
            file2.close();
            file3.close();
            file4.close();
        }
        else {
            file1.seekg(0);
            file2.seekg(0);
            file3.seekg(0);
            file4.seekg(0);
        }

        return good;
    }
    catch(exception& e) {
        m->errorOut(e, "Bayesian", "checkReleaseDate");
        exit(1);
    }
}
开发者ID:Cryomics-Lab,项目名称:mothur,代码行数:76,代码来源:bayesian.cpp


示例7: processPrimitivesWFN

/* ********************************************************************************************* */
void processPrimitivesWFN(ifstream &ifil,const int npr,int* &pricen,int* &primty,solreal* &prexp)
{
   alloc1DIntArray("pricen",npr,pricen);
   alloc1DIntArray("primty",npr,primty);
   alloc1DRealArray("prexp",npr,prexp);
   int count=0;
   int pos;
   /* Getting the primitive centers */
   pos=ifil.tellg();
   ifil.seekg(pos+20);
   for (int i=0; i<npr; i++) {
      ifil >> pricen[i];
      pricen[i]--;
      count++;
      if (count==20) {
         pos=ifil.tellg();
         ifil.seekg(pos+20);
         count=0;
      }
      //cout << pricen[i] << " ";
   }
   if ((npr%20)==0) {
      pos=ifil.tellg();
      ifil.seekg(pos-20);
   }
   /* Getting the primitive types */
   pos=ifil.tellg();
   ifil.seekg(pos+20);
   count=0;
   for (int i=0; i<npr; i++) {
      ifil >> primty[i];
      primty[i]--;
      count++;
      if (count==20) {
         pos=ifil.tellg();
         ifil.seekg(pos+20);
         count=0;
      }
      //cout << primty[i] << " ";
   }
   if ((npr%20)==0) {
      pos=ifil.tellg();
      ifil.seekg(pos-20);
   }
   /* Getting the primitive exponents */
   string line;
   int nolines;
   nolines=floor(npr/5);
   if ((npr%5)>0) {nolines++;}
   count=0;
   for (int i=0; i<nolines; i++) {
      pos=ifil.tellg();
      getline(ifil,line); 
      if (line.length()==0) {getline(ifil,line); pos++;}
      line.erase(0,10);
      for (int j=0; j<5; j++) {
         if (count<npr) {
            if ((line[10]=='D')||(line[10]=='d')) {
               line[10]='e';
            }
            prexp[count]=(solreal)atof((line.substr(0,14)).c_str());
            count++;
            line.erase(0,14);
         }
      }
   }
}
开发者ID:jmsolano,项目名称:denstoolkit,代码行数:68,代码来源:iofuncts-wfn.cpp


示例8: unserialize

bool Entity_CollisionType_Puzzle_Barrier::unserialize(ifstream& file)
{
    if(!file.is_open()) return false;
    int Entity_CollisionType_Puzzle_Barrier_version;
    file.read((char*) &Entity_CollisionType_Puzzle_Barrier_version, sizeof(int));
    if(Entity_CollisionType_Puzzle_Barrier_version==1){
        file.read((char*) &x, sizeof(x));
        file.read((char*) &y, sizeof(y));
        file.read((char*) &w, sizeof(w));
        file.read((char*) &h, sizeof(h));
        bounds.x = x-(w/2);
        bounds.y = y-(h/2);
        bounds.w = w;
        bounds.h = h;
        return true;
    }
    else if(Entity_CollisionType_Puzzle_Barrier_version==2){
        file.read((char*) &x, sizeof(x));
        file.read((char*) &y, sizeof(y));
        file.read((char*) &w, sizeof(w));
        file.read((char*) &h, sizeof(h));
        file.read((char*) &tied_respawn_zone_index, sizeof(tied_respawn_zone_index));
        bounds.x = x-(w/2);
        bounds.y = y-(h/2);
        bounds.w = w;
        bounds.h = h;

        return true;
    }
        else if(Entity_CollisionType_Puzzle_Barrier_version==3){
        file.read((char*) &x, sizeof(x));
        file.read((char*) &y, sizeof(y));
        file.read((char*) &w, sizeof(w));
        file.read((char*) &h, sizeof(h));
        file.read((char*) &tied_respawn_zone_index, sizeof(tied_respawn_zone_index));
        file.read((char*) &index, sizeof(index));
        bounds.x = x-(w/2);
        bounds.y = y-(h/2);
        bounds.w = w;
        bounds.h = h;

        return true;
    }
    else return false;
}
开发者ID:mvandevander,项目名称:duet,代码行数:45,代码来源:Entity_CollisionType_Puzzle_Barrier.cpp


示例9: initFromFileForMicroFluidic

void CellPositionInitialiser::initFromFileForMicroFluidic(Agent *ag, ifstream& input, ifstream& geo) {
	cerr << "#  starting all cells at a position based on a microfluidic file (initFromFileForMicroFluidic) " << endl;

	//go to the beginning of the file
	input.seekg(0,ios::beg);
	geo.seekg(0,ios::beg);

	// some local variables.
	string line = "";
	istringstream iss;
	string line2 = "";
	istringstream iss2;

	string from = ",";
	string to   = " ";
	size_t lookHere;
	size_t foundHere;

	int voxel_index = 0;
	int num_cells   = 0;
	int value       = 0;
	vector<double> coordinate(3);

	// get the database of the agent
	Database *db = ag->getDatabase();
	// get cell_positions
	TVectorData<TVectorData<double>* > *cell_positions =
			(TVectorData<TVectorData<double>* >*) db->getDataItem("cellpositions");
	// get environment grid
	Grid *g = (Grid *) db->getDataItem("environment");
	// get cell_voxel_positions
	TVectorData<int> *cell_voxel_positions = (TVectorData<int>* ) db->getDataItem("cell_voxel_positions");
	// get number cells_per_voxel
	TVectorData<int> *number_cells_per_voxel = (TVectorData<int>* ) db->getDataItem("number_cells_per_voxel");
	number_cells_per_voxel->reserveSize(g->getNumberOfVoxels());
	for (int i=0; i<g->getNumberOfVoxels(); i++)
		number_cells_per_voxel->at(i) = 0;

	// iterate over the input
	while (getline(input,line)) {
		lookHere = 0;
		// remove comma delimiters and change them to empty spaces
		while ((foundHere = line.find(from, lookHere)) != string::npos) {
			line.replace(foundHere,from.size(),to);
			lookHere = foundHere + to.size();
		}
		// remove comma delimiters from geometry file
		getline(geo,line2);
		lookHere = 0;
		while ((foundHere = line2.find(from, lookHere)) != string::npos) {
			line2.replace(foundHere,from.size(),to);
			lookHere = foundHere + to.size();
		}
		iss.clear();      // cell input
		iss.str(line);
		iss2.clear(); 	  // geometry input
		iss2.str(line2);
		while (iss2 >> value) {
			iss >> num_cells;
			// if we have a real voxel
			if (value == 1) {
				// get the center coordinate of the voxel that we currently are dealing with
				g->getCenterOfVoxel(voxel_index++, coordinate);
				// add cells to the system
				for (int i=0; i<num_cells; i++) {
					// add a position to the cell positions vector
					TVectorData<double> *pos = new TVectorData<double>("position", "tvectordata_double");
					pos->reserveSize(3);
					pos->at(0) = coordinate[0]; pos->at(1) = coordinate[1]; pos->at(2) = coordinate[2];
					cell_positions->addElementToEnd(pos);
					// add an entry to the cell_voxel_positions vector
					cell_voxel_positions->addElementToEnd(voxel_index-1);
					// update number cells per voxel
					number_cells_per_voxel->at(voxel_index-1) = number_cells_per_voxel->at(voxel_index-1) + 1;
				}
			}
		}
	}
	// set the numberofcells to the correct value
	IntegerData *nc = (IntegerData*) db->getDataItem("numberofcells");
	nc->setInteger(cell_positions->size());
	this->cellnumber = cell_positions->size();
	// initialise all the remaining vectors
	this->doTheRest(ag);
}
开发者ID:BHIVE,项目名称:BHIVE,代码行数:85,代码来源:cellpositioninitialiser.cpp


示例10: ifstream

int
csdb_generator::read_from (const char *srcfile)
{
  inf_ = new ifstream(srcfile);
  char *ptr;
  while (inf_->good() && !inf_->eof()) {
    linecounter_++;
    switch (read_line ()) {
    case -1: // bogus line
      fail ("unknown field tag");
      break;
    case 0: // comment or blank line
      break;
    case 1: // start
      entry_.desc_ = 0;
      entry_.loc_name_ = 0;
      entry_.codeset_id_ = 0;
      entry_.num_sets_ = 0;
      entry_.max_bytes_ = 0;
      in_entry_ = 1;
      break;
    case 2: // end
      if (entry_.codeset_id_ == 0)
        fail ("entry missing rgy_value");
      if (entry_.num_sets_ == 0)
        fail ("entry does not include at least one char_value");
      if (entry_.max_bytes_ == 0)
        fail ("entry does not define max_bytes");
      write_entry ();
      delete [] const_cast<char *> (entry_.desc_);
      delete [] const_cast<char *> (entry_.loc_name_);
      count_++;
      in_entry_ = 0;
      break;
    case 3: // description
      if (entry_.desc_ != 0)
        fail ("duplicate description");
      entry_.desc_ = ACE_OS::strdup(line_data_);
      break;
    case 4: // loc_name
      if (entry_.loc_name_ != 0)
        fail ("duplicate loc_name");
       entry_.loc_name_ = ACE_OS::strdup(line_data_);
       break;
    case 5: // rgy_value
      if (entry_.codeset_id_ != 0)
        fail ("duplicate rgy_value");
      entry_.codeset_id_ = ACE_OS::strtoul(line_data_,&ptr,16);
      if (*ptr != 0 || entry_.codeset_id_ == 0)
        {
          char emsg [100];
          ACE_OS::sprintf (emsg,"invalid rgy_value, '%s'",line_data_);
          fail (emsg);
        }
      break;
    case 6: // char_values
      if (entry_.num_sets_ != 0)
        fail ("duplicate char_values");
      ptr = line_data_;
      do {
        if (*ptr == ':')
          ptr++;
        ACE_CDR::UShort tmp =
          static_cast<ACE_CDR::UShort> (ACE_OS::strtoul(ptr,&ptr,16));
        if (*ptr != 0 && *ptr != ':')
          {
            char *emsg = new char [100];
            ACE_OS::sprintf (emsg,"invalid symbol \'%c\' in char_values",*ptr);
            fail (emsg);
          }
        if (entry_.num_sets_ < max_charsets_)
          entry_.char_sets_[entry_.num_sets_++] = tmp;
        else entry_.num_sets_++;
      } while (*ptr == ':');
      if (entry_.num_sets_ > max_charsets_)
        {
          char *emsg = new char [200];
          ACE_OS::sprintf (emsg,"max of %d char_values exceeded.\nIncrease ACE_Codeset_Registry::max_charsets_ to at least %d and rebuild mkcsregdb",max_charsets_,entry_.num_sets_);
          fail (emsg);
        }
      break;
    case 7: // max_bytes
      if (entry_.max_bytes_ != 0)
        fail ("duplicate max_bytes");
      entry_.max_bytes_ =
        static_cast<ACE_CDR::UShort> (ACE_OS::strtol(line_data_,&ptr,10));
      if (*ptr != 0)
        fail ("invalid max_bytes");
      break;
    }
  }
  return 0;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:93,代码来源:mkcsregdb.cpp


示例11: closefiles

//********************************************************************************************************************
//********************************************************************************************************************
void closefiles(ifstream& files, ofstream& outfile, ofstream& errorfile) {
	files.close();
	outfile.close();
	errorfile.close();
}
开发者ID:SaltLakeAtrocity,项目名称:CSC205,代码行数:7,代码来源:Programming_Assignment_Three.cpp


示例12: load

void load(ifstream &f,mint &elementos, mdouble &nodos, mdouble &contorno){
	
	nodos.clear();
	elementos.clear();
	contorno.clear();
	/// VARIABLES
	int n,o,p;
	char t[100];
	double x;
	
	/// CARGAMOS LAS VARIABLES GENERALES DEL PROBLEMA
	f.getline(t,100);
	e = atof(t); /// TOLERANCIA
	f.getline(t,100);
	iteraciones = atoi(t); /// ITERACIONES MAXIMAS
	f.getline(t,100);
	dt = atof(t); /// PASO DE TIEMPO
	f.getline(t,100);
	Re = atof(t); /// NUMERO DE REYNOLDS
	
	/// LEEMOS LA CANTIDAD DE NODOS
	f.getline(t,100);
	n = atoi(t);
	/// ASIGNAMOS LOS NODOS
	for(int i=0;i<n;i++){
		vector<double> nod;
		/// COORDENADA X
		f.getline(t,100);
		x = atof(t);
		nod.push_back(x);
		/// COORDENADA Y
		f.getline(t,100);
		x = atof(t);
		nod.push_back(x);
		nodos.push_back(nod);
	}
	
	/// LEEMOS LA CANTIDAD DE ELEMENTOS
	f.getline(t,100);
	n = atoi(t);
	
	/// LEEMOS LA CANTIDAD DE NODOS POR ELEMENTO
	f.getline(t,100);
	o = atoi(t);
	
	/// LEEMOS LOS INDICES DE LOS ELEMENTOS
	for(int i=0;i<n;i++){
		vector<int> e;
		f.getline(t,100);
		char *ptr;
		/// LOS NUMEROS DE LOS NODOS ESTAN SEPARADOS POR UN ESPACIO
		ptr = strtok(t," ");
		p = atoi(ptr);
		e.push_back(p-1);
		for(int j=0;j<o-1;j++){
			// mandarle un null parece que hace que continue con el puntero del anterior strtok
			ptr = strtok(NULL," ");
			p = atoi(ptr);
			e.push_back(p-1);
		}
		elementos.push_back(e);
	}
	/// LEEMOS LAS CONDICIONES DE CONTORNO
	
	/// LA ORGANIZACION DEL CONTORNO ES
	/// NumNodo TipoFront Valores
	
	/// LEEMOS LA CANTIDAD DE NODOS CON WALL
	f.getline(t,100);
	n = atoi(t);
	for(int i=0;i<n;i++){
		vector<double> nContorno;
		/// NODO 1
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// NODO 2
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// TIPO DE CONTORNO
		nContorno.push_back(1.0);
		/// ASIGNAMOS u = v = 0 porque es wall
		nContorno.push_back(.0);
		nContorno.push_back(.0);
		contorno.push_back(nContorno);
	}
	
	/// LEEMOS LA CANTIDAD DE NODOS CON VELOCIDAD IMPUESTA
	f.getline(t,100);
	n = atoi(t);
	for(int i=0;i<n;i++){
		vector<double> nContorno;
		/// NODO 1
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// NODO 2
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// TIPO DE CONTORNO
		nContorno.push_back(1.0);
		/// LEEMOS u
//.........这里部分代码省略.........
开发者ID:pacha47,项目名称:ProyectoFinalCodigos,代码行数:101,代码来源:main.cpp


示例13: read_line

static string read_line(ifstream &file){
  static char buffer[BUFFER_SIZE];
  file.get(buffer,BUFFER_SIZE);
  file.get();
  return string(buffer);
}
开发者ID:Acidburn0zzz,项目名称:code,代码行数:6,代码来源:retriever.cpp


示例14: pgmb_read_data

bool pgmb_read_data ( ifstream &input, int xsize, int ysize, 
  unsigned char *g )

//****************************************************************************80
//
//  Purpose:
//
//    PGMB_READ_DATA reads the data in a binary portable gray map file.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license. 
//
//  Modified:
//
//    16 December 2004
//
//  Author:
//
//    John Burkardt
//
//  Parameters:
//
//    Input, ifstream &INPUT, a pointer to the file containing the binary
//    portable gray map data.
//
//    Input, int XSIZE, YSIZE, the number of rows and columns of data.
//
//    Output, unsigned char *G, the array of XSIZE by YSIZE data values.
//
//    Output, bool PGMB_READ_DATA, is true if an error occurred.
//
{
  char c;
  bool error;
  int i;
  unsigned char *indexg;
  int j;

  indexg = g;

  for ( j = 0; j < ysize; j++ )
  {
    for ( i = 0; i < xsize; i++ )
    {
      input.read ( &c, 1 );
      *indexg = ( unsigned char ) c;
      indexg = indexg + 1;
      error = input.eof();
      if ( error )
      {
        cout << "\n";
        cout << "PGMB_READ_DATA - Fatal error!\n";
        cout << "  End of file reading pixel (" 
          << i << ", " << j <<") \n";
        return true;
      }
    }
  }
  return false;
}
开发者ID:Vishakha6,项目名称:jburkardt-cpp,代码行数:61,代码来源:pgmb_to_pgma.cpp


示例15: pgmb_read_header

bool pgmb_read_header ( ifstream &input, int *xsize, int *ysize, 
  unsigned char *maxg )

//****************************************************************************80
//
//  Purpose:
//
//    PGMB_READ_HEADER reads the header of a binary portable gray map file.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license. 
//
//  Modified:
//
//    16 April 2003
//
//  Author:
//
//    John Burkardt
//
//  Parameters:
//
//    Input, ifstream &INPUT, a pointer to the file containing the binary
//    portable gray map data.
//
//    Output, int *XSIZE, *YSIZE, the number of rows and columns of data.
//
//    Output, unsigned char *MAXG, the maximum gray value.
//
//    Output, bool PGMB_READ_HEADER, is true if an error occurred.
//
{
  int count;
  int fred;
  string line;
  int maxg2;
  string rest;
  int step;
  int width;
  string word;

  step = 0;

  while ( 1 )
  {
    getline ( input, line );

    if ( input.eof ( ) )
    {
      cout << "\n";
      cout << "PGMB_READ_HEADER - Fatal error!\n";
      cout << "  End of file.\n";
      return true;
    }

    if ( line[0] == '#' )
    {
      continue;
    }

    if ( step == 0 )
    {
      s_word_extract_first ( line, word, rest );

      if ( s_len_trim ( word ) <= 0 )
      {
        continue;
      }

      if ( !s_eqi ( word, "P5" ) )
      {
        cout << "\n";
        cout << "PGMB_READ_HEADER - Fatal error.\n";
        cout << "  Bad magic number = \"" << word << "\".\n";
        return true;
      }
      line = rest;
      step = 1;
    }

    if ( step == 1 )
    {
      s_word_extract_first ( line, word, rest );
 
      if ( s_len_trim ( word ) <= 0 )
      {
        continue;
      }
      *xsize = atoi ( word.c_str ( ) );
      line = rest;
      step = 2;
    }

    if ( step == 2 )
    {
      s_word_extract_first ( line, word, rest );

      if ( s_len_trim ( word ) <= 0 )
      {
//.........这里部分代码省略.........
开发者ID:Vishakha6,项目名称:jburkardt-cpp,代码行数:101,代码来源:pgmb_to_pgma.cpp


示例16: openFile

bool openFile(ifstream & stream, string filename) {
   stream.clear();
   stream.open(expandPathname(filename).c_str());
   return !stream.fail();
}
开发者ID:zmukwa,项目名称:stanford-whittier-cpplib,代码行数:5,代码来源:filelib.cpp


示例17: readWordEmbeddings

void Labeler::readWordEmbeddings(const string& inFile, NRMat<double>& wordEmb) {
  static ifstream inf;
  if (inf.is_open()) {
    inf.close();
    inf.clear();
  }
  inf.open(inFile.c_str());

  static string strLine, curWord;
  static int wordId;

  //find the first line, decide the wordDim;
  while (1) {
    if (!my_getline(inf, strLine)) {
      break;
    }
    if (!strLine.empty())
      break;
  }

  int unknownId = m_wordAlphabet.from_string(unknownkey);

  static vector<string> vecInfo;
  split_bychar(strLine, vecInfo, ' ');
  int wordDim = vecInfo.size() - 1;

  std::cout << "word embedding dim is " << wordDim << std::endl;
  m_options.wordEmbSize = wordDim;

  wordEmb.resize(m_wordAlphabet.size(), wordDim);
  wordEmb = 0.0;
  curWord = normalize_to_lowerwithdigit(vecInfo[0]);
  wordId = m_wordAlphabet.from_string(curWord);
  hash_set<int> indexers;
  double sum[wordDim];
  int count = 0;
  bool bHasUnknown = false;
  if (wordId >= 0) {
    count++;
    if (unknownId == wordId)
      bHasUnknown = true;
    indexers.insert(wordId);
    for (int idx = 0; idx < wordDim; idx++) {
      double curValue = atof(vecInfo[idx + 1].c_str());
      sum[idx] = curValue;
      wordEmb[wordId][idx] = curValue;
    }

  } else {
    for (int idx = 0; idx < wordDim; idx++) {
      sum[idx] = 0.0;
    }
  }

  while (1) {
    if (!my_getline(inf, strLine)) {
      break;
    }
    if (strLine.empty())
      continue;
    split_bychar(strLine, vecInfo, ' ');
    if (vecInfo.size() != wordDim + 1) {
      std::cout << "error embedding file" << std::endl;
    }
    curWord = normalize_to_lowerwithdigit(vecInfo[0]);
    wordId = m_wordAlphabet.from_string(curWord);
    if (wordId >= 0) {
      count++;
      if (unknownId == wordId)
        bHasUnknown = true;
      indexers.insert(wordId);

      for (int idx = 0; idx < wordDim; idx++) {
        double curValue = atof(vecInfo[idx + 1].c_str());
        sum[idx] = curValue;
        wordEmb[wordId][idx] += curValue;
      }
    }

  }

  if (!bHasUnknown) {
    for (int idx = 0; idx < wordDim; idx++) {
      wordEmb[unknownId][idx] = sum[idx] / count;
    }
    count++;
    std::cout << unknownkey << " not found, using averaged value to initialize." << std::endl;
  }

  int oovWords = 0;
  int totalWords = 0;
  for (int id = 0; id < m_wordAlphabet.size(); id++) {
    if (indexers.find(id) == indexers.end()) {
      oovWords++;
      for (int idx = 0; idx < wordDim; idx++) {
        wordEmb[id][idx] = wordEmb[unknownId][idx];
      }
    }
    totalWords++;
  }
//.........这里部分代码省略.........
开发者ID:dram218,项目名称:NNSalientEvent,代码行数:101,代码来源:HWordDetector.cpp


示例18: readSOFT

void readSOFT(ifstream& input){
	string BAM_line;
	string ori1,chr1,begin1,ori2,chr2,begin2, end1, end2, num_t;
	string ori1_t,chr1_t,begin1_t,ori2_t,chr2_t,begin2_t, end1_t, end2_t;
	int b, e;
	int flag=0;
	ofstream Out_SOFT("Only_SOFT");
	while(!input.eof()){
		getline(input, BAM_line);
		if(BAM_line.length()==0)  //in case of a blank line
			break;
		istringstream ss(BAM_line);
		ss >> chr1_t >> begin1_t >> ori1_t >> chr2_t >> begin2_t >> ori2_t >> num_t;
		//ss >> ori1_t >> chr1_t >> begin1_t >> ori2_t >> chr2_t >> begin2_t >> name >> qua;
		if(chr1_t == chr2_t && atoi(begin1_t.c_str()) <= atoi(begin2_t.c_str()) || chr1_t < chr2_t){
			ori1 = ori1_t;
			chr1 = chr1_t;
			begin1 = begin1_t;
			ori2 = ori2_t;
			chr2 = chr2_t;
			begin2 = begin2_t;
		}
		else{
			ori1 = ori2_t;
			chr1 = chr2_t;
			begin1 = begin2_t;
			ori2 = ori1_t;
			chr2 = chr1_t;
			begin2 = begin1_t;
		}
		if(atoi(num_t.c_str()) < FINAL_SOFT_cut){
			continue;
		}
		interval const*i1;
		interval const*i2; 
		int flag_ = 0;
		//	string tt_1 = chr1+"\t"+chr2+"\t"+ori1+"\t"+ori2;
		//string tt_1 = chr1+"\t"+chr2;
		//string tt_2 = chr2+"\t"+chr1;
		if(ori1 == "+"){
			ori1 = "-";
		}
		else{
			ori1 = "+";
		}
		if(ori2 == "+"){
			ori2 = "-";             
		}
		else{
			ori2 = "+";
		}
		string tt_1 = chr1+"\t"+chr2+"\t"+ori1+"\t"+ori2;

		if(ori1 == "-"){
			i1 = find_flag(all_bed_1[tt_1]["-"], atoi(begin1.c_str())+50, ori1);
		}
		else{
			i1 = find_flag(all_bed_1[tt_1]["+"], atoi(begin1.c_str())-50,ori1);
		}
		if(ori2 == "-"){
			i2 = find_flag(all_bed_2[tt_1]["-"], atoi(begin2.c_str())+50,ori2);
		}
		else{
			i2 = find_flag(all_bed_2[tt_1]["+"], atoi(begin2.c_str())-50,ori2);
		}
		if(i1 != NULL && i2 != NULL){
			set<interval>::iterator it_1, it_2;
			for(it_1 = all_bed_1[tt_1][ori1][(*i1)].begin(); it_1!= all_bed_1[tt_1][ori1][(*i1)].end(); it_1++){
				for(it_2 = all_bed_2[tt_1][ori2][(*i2)].begin(); it_2!= all_bed_2[tt_1][ori2][(*i2)].end(); it_2++){
					ostringstream key;
					key.clear();
					key << chr1 << "\t" << (*it_1).start << "\t" << (*it_1).end << "\t" << ori1 << "\t" << chr2 << "\t" << (*it_2).start << "\t" << (*it_2).end << "\t" << ori2;
					if(ALL.find(key.str()) != ALL.end()){
						int a,b,c,d;
						if(ori1 == "+"){
							a = (*it_1).start;
							b = atoi(begin1.c_str());
						}
						else{
							a = atoi(begin1.c_str());
							b = (*it_1).end;
						}
						if(ori2 == "+"){
							c = (*it_2).start;
							d = atoi(begin2.c_str());
						}
						else{
							c = atoi(begin2.c_str());
							d = (*it_2).end;
						}
						ostringstream key2;
						key2.clear();
						key2 << chr1 << "\t" << a << "\t" << b << "\t" << ori1 << "\t" << chr2 << "\t" << c << "\t" << d << "\t" << ori2;
						ostringstream alt;//final format chr1 pos1 ori1 chr2 pos2 ori2
						alt << chr1 << "\t";
						if(ori1 == "+")
							alt << b;
						else
							alt << a;
						alt << "\t" << ori1 << "\t" << chr2 << "\t";
//.........这里部分代码省略.........
开发者ID:asadrahman-horizon,项目名称:Weaver,代码行数:101,代码来源:combineSuperPair.cpp


示例19: load

int TFoul::load( ifstream &ifs, vector<TPlayer*> &HomePlayer, vector<TPlayer*> &GuestPlayer )
{
    unsigned int i;
    string line;
    while(ifs.good())
    {
        line = TTools::ReadUnspaced(ifs);
        if ( TTools::strcontain( line,"</Foul>" ) )
        {
            #ifdef DEBUG
                cout << line << endl;
            #endif
            return 1;
        }
        else if( TTools::strcontain( line,"<MinuteOfPlay>" ) )
        {
            #ifdef DEBUG
            

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ihash类代码示例发布时间:2022-05-31
下一篇:
C++ idx类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap