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


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

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


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

示例1: numberize

// A little procedure to read floating point numbers from an input string
double numberize(std::ifstream& input, int &precise)
{
  char c;
  double number = 0;
  bool negative, after;

  precise = 0;
  negative = after = false;
  
  // Pass SPACE-characters
  while (((c = input.get()) == ' ') || (c == '\n'));

  // Read double-type number from input-stream
  if (c == '-') negative = true;
  while((c != ' ') && 
	(c != '\n') && 
	(!input.eof())) {
    if (c == '.') after = true;
    else if ((c < 48) || (c > 57)) number = -1; //return;
    else {
      //  cout << c;
      number = (number * 10) + (c - 48);
      if (after) precise++;
    }
    c = input.get();
  }

  number = number * pow(10,(-precise));
  if (negative) number = -number;
  // cout << "\nNumber is: " << number << endl;
  return number;
}
开发者ID:ClarkWang12,项目名称:object-proposals,代码行数:33,代码来源:basic_calls.cpp

示例2: LoadParameters

void Entite_graphique::LoadParameters(std::ifstream &fichier)
{
    char caractere;
    do
    {
        fichier.get(caractere);
        if(caractere == 't')
        {
            fichier.get(caractere);
            if(caractere == 'x')
                fichier>>m_decalage.x;
            if(caractere == 'y')
                fichier>>m_decalage.y;
        }
        if(caractere == 's')
        {
            fichier.get(caractere);
            if(caractere == 'x')
                fichier>>m_scale.x;
            if(caractere == 'y')
                fichier>>m_scale.y;

            if(m_scale.x == 0)
                m_scale.x = 100;
            if(m_scale.y == 0)
                m_scale.y = 100;
        }
开发者ID:q4a,项目名称:holyspirit-trunk,代码行数:27,代码来源:Entite_graphique.cpp

示例3: getNextWord

void getNextWord(std::ifstream& inFile, std::string& token, std::string tokenizer, int64_t endOffSet)
{
   token.clear();
   char byte[1];

  while(inFile.good())
  {
     if(inFile.tellg() >= endOffSet)
       return;

     byte[0] =inFile.peek();
     if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
       inFile.get();
     }else{
       break;
     }
  }


  while(inFile.good()){
   byte[0] = inFile.get();   
   if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
     return;
   }
    token.append(byte,1);
   }
}
开发者ID:innosam,项目名称:beehive,代码行数:27,代码来源:MapReduce.cpp

示例4: getVar

std::string CppLogger::getVar(std::ifstream& file)
{
	std::string result = "";

	while (file.good())
	{
		char c = file.get();
		if (c == '=' || c == '\n')
		{
			break;
		}
		else if (c == '#')
		{
			while (file.good() && file.get() != '\n')
			{
			}
			break;
		}
		else if (c == ' ')
		{
			continue;
		}

		result += c;
	}

	return result;
}
开发者ID:skoczo,项目名称:CppLogger,代码行数:28,代码来源:CppLogger.cpp

示例5: strip_file

/******************************************************************************************************
void strip_file(std::ifstream& inStream, std::string fileName)

Description: Opens a input file and strips symbols and outputs to temp file.

Parameters: std::ifstream& inStream, std::string fileName

Pre-Conditions: Input file must be opened.
Post-Conditions: Input file will be stripped of symnbols and output to temp file.
******************************************************************************************************/
void strip_file(std::ifstream& inStream, std::fstream& tempStream)
{
    std::vector<char> lines;//create a vector to hold characters.

    while (inStream)//iterate through each line in file.
    {
	   char ch;
	   int count = 0;
	   ch = inStream.get();//Get character from line.
	   while (ch != EOF)//While not end of line.
	   {
		  if (ch != ',' && ch != '[' && ch != ']')//Do not add these symbols.
		  {
			 lines.push_back(ch);//Push character to vector.
			 count++;//inc count, used to loop through vector.
		  }
		  ch = inStream.get();//get next char in line.
	   }
	   for (int i = 0; i < count; i++)
	   {

		  //std::cout << lines[i];  //Outputs each line in file to console.
		  tempStream << lines[i];//Outputs to temp.txt file

	   }
	   lines.clear();//Clears the vector of all values.
    }
    inStream.clear();//clears the end of file flag (eof).
    inStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream.
    tempStream.clear();//clears the end of file flag (eof).
    tempStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream.

}//end strip_file
开发者ID:Lagrewj,项目名称:CS325_Project2,代码行数:43,代码来源:file_action.cpp

示例6: readFileCounts

AnimatedObjModel::DataCounts AnimatedObjModel::readFileCounts(std::ifstream& _dataStream)
{	
	DataCounts counts;

	char tInput;
	counts.positions = 0;
	counts.texCoords = 0;
	counts.normals = 0;
	counts.faces = 0;
	counts.groups = 0;
	counts.bones = 0;

	_dataStream.get(tInput);
	while(!_dataStream.eof())
	{
		if(tInput == 'v')
		{
			_dataStream.get(tInput);
			if(tInput == ' ') 
			{
				counts.positions++;
			}

			if(tInput == 't')
			{
				counts.texCoords++;
			}

			if(tInput == 'n')
			{
				counts.normals++;
			}
		}

		if(tInput == 'g')
		{
			counts.groups++;
		}

		if(tInput == 'f')
		{
			counts.faces++;
		}

		if (tInput == 'b')
		{
			counts.bones++;
		}

		while(tInput != '\n')
		{
			_dataStream.get(tInput);
		}

		_dataStream.get(tInput);
	}

	return counts;
}
开发者ID:Jereq,项目名称:Raytracer,代码行数:59,代码来源:AnimatedObjModel.cpp

示例7: if

int
MiscReadCharsAndDoubleFromFile(
  std::ifstream& ifs,
  std::string&   termString,
  double*        termValue,
  bool&          endOfLineAchieved)
{
  int iRC = UQ_OK_RC;
  endOfLineAchieved = false;

  char c = ' ';
  while (c == ' ') {
    ifs.get(c);
    if ((ifs.rdstate() & std::ifstream::failbit)) {
      iRC = UQ_FAILED_READING_FILE_RC;
      break;
    }
  };

  char term[512];
  unsigned int pos = 0;

  if (!iRC) {
    while ((pos < 512) && (c != '\n') && (c != '\0') && (c != ' ')) {
      term[pos++] = c;
      if ((ifs.rdstate() & std::ifstream::failbit)) {
        iRC = UQ_FAILED_READING_FILE_RC;
        break;
      }
      ifs.get(c);
    };
  }

  if (!iRC) {
    if (c == '\n') endOfLineAchieved = true;
    term[pos] = '\0';
    termString = term;
    //std::cout << "Read chars = " << termString << std::endl;
    if (termValue) {
      if (termString == std::string("inf")) {
        *termValue = INFINITY;
      }
      else if (termString == std::string("-inf")) {
        *termValue = -INFINITY;
      }
      else if (termString == std::string("nan")) {
        *termValue = nan("");
      }
      else {
        *termValue = strtod(termString.c_str(),NULL);
      }
    }
  }

  return iRC;
}
开发者ID:brianw525,项目名称:queso,代码行数:56,代码来源:Miscellaneous.C

示例8: readLine

	std::string readLine(std::ifstream &in_)
	{
		std::string result = "";
		while (in_.peek() != '\n' && in_.eof() == false)
		{
			result += in_.get();
		}
		in_.get();
		return result;
	}
开发者ID:CStanKonrad,项目名称:CStanKonradLibrary,代码行数:10,代码来源:Directory.cpp

示例9: Get_Rest_Of_File_As_String

std::string Get_Rest_Of_File_As_String(std::ifstream & infile){
	std::string data;
	char temp = infile.get();
	while(infile){
		data+=temp;
		temp = infile.get();
	}

	return data;
}
开发者ID:UniLang,项目名称:control-structure-printer,代码行数:10,代码来源:filestreams.cpp

示例10: populate

void state::populate(std::ifstream &file)
{
	char row[50], *p, temp[5];
	char ipSymbol = 'a', ip;
	int s;
	file.get(op);
	file.get();
	file.getline(row, 50);
	p = row;
	while(*p!='\0')
	{
		std::sscanf(p, "%s", temp);
		if(temp[0] == '~')
		{
		}
		else if(temp[0] == 'F')
		{
			finalState = true;
		}
		else
		{
			tCount++;
			ip = ipSymbol;
			s = temp[0] - 48;
			transitionTable = (struct transition *) std::realloc(transitionTable, sizeof(transition) * tCount);
			transitionTable[tCount - 1].ip = ip;
			transitionTable[tCount - 1].t = s + 48;
			/*
			if(s < sCount)		//Transiting to a preceding state
			{
				transitionTable[tCount - 1].t = s + 48;
			}
			else
			{
				refTable = (struct globalRef *) std::realloc(refTable, sizeof(globalRef) * (s+1));
//				refTable[s].addr = new state;
				transitionTable[tCount - 1].t = refTable[s].stateName = s + 48;
			}
			*/
		}

		while(*p != ' ')
		{
			if(*p == '\0')
			{
				p--;
				break;
			}
			p++;
		}
		p++;

		ipSymbol++;
	}
}
开发者ID:safiyat,项目名称:CompilerDesignLab,代码行数:55,代码来源:state.cpp

示例11: loadDataStructures

void AnimatedObjModel::loadDataStructures(std::ifstream& _dataStream, const DataCounts& counts)
{
	std::vector<glm::vec3> tVertices;
	std::vector<glm::vec2> tTexCoords;
	std::vector<glm::vec3> tNormals;
	std::vector<FaceType> tFaces;

	char tInput1;
	
	int tVertexIndex = 0;
	int tTexcoordIndex = 0;
	int tNormalIndex = 0;
	int tFaceIndex = 0;
	int tBoneIndex = 0;

	mModel.resize(counts.faces * 3);

	//Initialize the four data structures.
	tVertices.resize(counts.positions);
	tTexCoords.resize(counts.texCoords);
	tNormals.resize(counts.normals);
	tFaces.resize(counts.faces);
	bones.resize(counts.bones);

	while(_dataStream)
	{
		_dataStream.get(tInput1);

		if (tInput1 == '#')
		{
#undef max
			_dataStream.ignore(std::numeric_limits<int>::max(), '\n');
			continue;
		}

		if(tInput1 == 'v')
		{
			_dataStream.get(tInput1);

			//Read in the vertices.
			if(tInput1 == ' ') 
			{ 
				_dataStream >> tVertices[tVertexIndex].x;
				_dataStream >> tVertices[tVertexIndex].y;
				_dataStream >> tVertices[tVertexIndex].z;
				tVertexIndex++; 
			}

			//Read in the texture uv coordinates.
			if(tInput1 == 't') 
			{ 
				_dataStream >> tTexCoords[tTexcoordIndex].x;
				_dataStream >> tTexCoords[tTexcoordIndex].y;
				tTexcoordIndex++; 
			}
开发者ID:Jereq,项目名称:Raytracer,代码行数:55,代码来源:AnimatedObjModel.cpp

示例12: angleBracket

//the case if encounter a angle bracket "["
void MDparser::angleBracket(std::string& tobeStored, bool& readyToStore, std::ifstream& myinput, myset<std::string>& allWords, myset<std::string>& allLinks){
	string buffer("");

    char letter=(char)myinput.get();
    while(letter!=']'&& !myinput.fail()){
      buffer=buffer+letter;
      letter=(char)myinput.get();
   }
   buffer+="]";
   //parsing,change bool varibale to false
   for (int i=0;i<(int)buffer.size();i++){
   		letter=buffer[i];
   		if(isLetter(letter)){
   			readyToStore=true;
   			tobeStored+=letter;
   		}
   		else if(!isLetter(letter)&&readyToStore){
   			allWords.insert(tobeStored);
   			tobeStored="";
   			readyToStore=false;
   		}
   		else if(!isLetter(letter)&&!readyToStore){
   			//donothing
   		}
   }

   if(!myinput.fail()){
   	   letter=(char)myinput.get(); //get the next letter after']'
		if(letter=='('){
			buffer="";
			letter=(char)myinput.get();
			while(letter!=')'){
				buffer+=letter;
				letter=(char)myinput.get();
			}
			ifstream my_input(buffer.c_str());
			if(!my_input.fail()){
				allLinks.insert(buffer);				
			}
			my_input.close();
			buffer="";
			readyToStore=false;
		}
		else{
			if(isLetter(letter)){
				readyToStore=true;
				tobeStored+=letter;
			}
			else{
				readyToStore=false;
			}
		}
   }
}
开发者ID:sean1996,项目名称:SearchEngine-PageRank,代码行数:55,代码来源:MDparser.cpp

示例13: CheckAndCompareFileString

bool TUtilities::CheckAndCompareFileString(std::ifstream &InFile, AnsiString InString)
//Reads the next item and checks it as a string value up to either the '\0' delimiter
//if there is one, in which case the '\0' is extracted but nothing more, or up to the next '\n',
//in which case the '\n' is extracted.  There may or may not be a '\n' at the start, and if there
//is it is ignored (only one is ignored, a second one is treated as a delimiter).
//The item is then compared with InString and fails if different.
{
char TempChar;
char *Buffer = new char[10000];
int Count = 0;
InFile.get(TempChar);//may or may not be '\n'
if(InFile.fail())
    {
    delete Buffer;
    return false;
    }
if(TempChar == '\n')
    {
    InFile.get(TempChar);//get the next one if first was '\n'
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
while((TempChar != '\0') && (TempChar != '\n'))
    {
    if((TempChar < 32) && (TempChar >= 0))
        {
        delete Buffer;
        return false;
        }
    Buffer[Count] = TempChar;
    Count++;
    InFile.get(TempChar);
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
Buffer[Count] = '\0';
Count++;
Buffer[Count] = '\n';
Count++;
if(AnsiString(Buffer) != InString)
    {
    delete Buffer;
    return false;
    }
delete Buffer;
return true;
}
开发者ID:jagercode,项目名称:railway-dot-exe,代码行数:53,代码来源:Utilities.cpp

示例14: LoadFileString

//---------------------------------------------------------------------------
AnsiString TUtilities::LoadFileString(std::ifstream &InFile)
{//see SaveFileString for use of the '\0' & '\n' characters
char TempChar;
AnsiString TempString = "";
InFile.get(TempChar); //get rid of the previous 'n' character, if not '\n' then use as part of string
if(TempChar == '\n') InFile.get(TempChar);
while(TempChar != '\0')//'\0' is the string delimiter
    {
    TempString = TempString + TempChar;
    InFile.get(TempChar);
    }
return TempString;
}
开发者ID:jagercode,项目名称:railway-dot-exe,代码行数:14,代码来源:Utilities.cpp

示例15: setSearchData

/*
----------------------------------setSearchData------------------------------
setSearchData - Sets information about an item, from a file formatted
                specifically containing action information.  This does
                not provide full details for a complete YouthBook.  It
                only allows for an item to be created with specific search
                criteria.

PreConditions: A validly formatted input file
PostConditions: Book information is updated from the file.
*/
bool YouthBook::setSearchData(std::ifstream& infile) {
    std::string inputAuthor, inputTitle;

    infile.get();
    getline(infile, inputTitle, FIELD_SEPARATOR);
    infile.get();
    getline(infile, inputAuthor, FIELD_SEPARATOR);
    setAuthor(inputAuthor);
    setName(inputTitle);

    //getline(infile, inputTitle);
    return true;
}
开发者ID:patkaehuaea,项目名称:UWBothell_CSS502_AS3,代码行数:24,代码来源:youthbook.cpp


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