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


C++ istream::getline方法代码示例

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


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

示例1: readLine

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int32_t VtkStructuredPointsReader::readLine(std::istream& in, char* result, size_t length)
{
  in.getline(result, length);
  if (in.fail())
  {
    if (in.eof())
    {
      return 0;
    }
    if (in.gcount() == length)
    {
      // Read kBufferSize chars; ignoring the rest of the line.
      in.clear();
      in.ignore(std::numeric_limits<int>::max(), '\n');
    }
  }
  return 1;
}
开发者ID:BlueQuartzSoftware,项目名称:DREAM3D,代码行数:21,代码来源:VtkStructuredPointsReader.cpp

示例2: readFastaEntry

void readFastaEntry(std::istream& i,
		    std::string& name,
		    std::string& description,
		    std::string& sequence)
  throw (ParseException)
{
    char ch;
    char c[512];

    i.getline(c, 511);
    if (i) {
      if (c[0] != '>') {
	throw ParseException(std::string("FASTA file expected '>', got: '")
			     + c[0] + "'");
      }

      std::string nameDesc = c + 1;
      std::string::size_type spacepos = nameDesc.find(" ");
      name = nameDesc.substr(0, spacepos);
      description = (spacepos == std::string::npos
		     ? ""
		     : nameDesc.substr(spacepos));

      for (ch = i.get(); (ch != EOF) && (ch != '>'); ch = i.get()) {
	if ((ch != '\n') && (ch != '\r') && (ch != ' ')) {
	  if (((ch >= 'a') && (ch <= 'z'))
	      || ((ch >= 'A') && (ch <= 'Z'))
	      || (ch == '-') || (ch == '*')) {
	    sequence += ch;
	  } else {
	    throw ParseException
	      (std::string("Illegal character in FASTA file: '")
	       + (char)ch + "'");
	  }
	}

	if (i.peek() == EOF)
	  break;
      }

      if (ch == '>')
	i.putback(ch);
    }
}
开发者ID:HKU-BAL,项目名称:megagta,代码行数:44,代码来源:NTSequence.C

示例3: ZlibDecompress

    void Compression::ZlibDecompress (std::istream& is, std::ostream& os)
    {
	char buffer[32];
	is.getline (buffer, sizeof(buffer), '#');
	int size (atoi (buffer));
	if (size == 0) return;

	filtering_stream<input> fs;

	fs.push (zlib_decompressor());
	fs.push (restrict (is, 0, size));

	boost::iostreams::copy(fs, os);
	// fs.set_auto_close (false);
	fs.pop ();

	// Warning filtering stream is closed at destruction causing all underlying device to be clolsed as well.

    }
开发者ID:Tisseo,项目名称:synthese,代码行数:19,代码来源:Compression.cpp

示例4: continueParse

void LLMimeParser::Impl::scanPastSeparator(
	std::istream& istr,
	S32 limit,
	const std::string& sep)
{
	std::ostringstream ostr;
	ostr << SEPARATOR_PREFIX << sep;
	std::string separator = ostr.str();
	bool found_separator = false;
	while(!found_separator && continueParse())
	{
		// Subtract 1 from the limit so that we make sure not to read
		// past limit when we get() the newline.
		S32 max_get = llmin((S32)LINE_BUFFER_LENGTH, limit - mScanCount - 1);
		istr.getline(mBuffer, max_get, '\r');
		mScanCount += istr.gcount();
		if(istr.gcount() >= LINE_BUFFER_LENGTH - 1)
		{
			// that's way too long to be a separator, so ignore it.
			continue;
		}
		int c = istr.get();
		if(EOF == c)
		{
			mContinue = false;
			return;
		}
		++mScanCount;
		if(c != '\n')
		{
			mError = true;
			return;
		}
		if(mScanCount >= limit)
		{
			mContinue = false;
		}
		if(0 == LLStringUtil::compareStrings(std::string(mBuffer), separator))
		{
			found_separator = true;
		}
	}
}
开发者ID:Nora28,项目名称:imprudence,代码行数:43,代码来源:llmime.cpp

示例5: while

void
cpu_tsdf::Octree::deserialize (std::istream &f)
{
  std::string root_type;
  f >> root_type;
  root_.reset (OctreeNode::instantiateByTypeString (root_type));
  char tmp[1024];
  do
  {
    f.getline (tmp, 1024);
  }
  while (!(tmp[0] == '#' && tmp[1] == 'O'));
  f.read ((char*)&res_x_, sizeof (size_t));
  f.read ((char*)&res_y_, sizeof (size_t));
  f.read ((char*)&res_z_, sizeof (size_t));
  f.read ((char*)&size_x_, sizeof (float));
  f.read ((char*)&size_y_, sizeof (float));
  f.read ((char*)&size_z_, sizeof (float));
  root_->deserialize (f);
}
开发者ID:roboticlab,项目名称:object_scanner,代码行数:20,代码来源:octree.cpp

示例6: LoadFromVxo

void gl_mesh::LoadFromVxo(std::istream & File)
{
	// float must be 32 bits
	static_assert(sizeof(char) == sizeof(uint8_t));
	static_assert(sizeof(float) == sizeof(uint32_t));

	using io_facilities::readvar;
	
	// Mesh Name
	char String[256];
	File.getline(String, 256, '\0');
	m_Name = String;

	// Mesh Info
	size_t NbSubMeshes;
	readvar(File, NbSubMeshes, 4);
	readvar(File, m_NbVertices, 4);
	readvar(File, m_NbTextures, 4);

	m_SubMeshes.resize(NbSubMeshes);
	m_VArrays[vertex].resize(3 * m_NbVertices);
	m_VArrays[normal].resize(3 * m_NbVertices);

	for (size_t i = 0; i < m_NbTextures; ++i)
		m_VArrays[array_type(texture_coord0 + i)].resize(2 * m_NbVertices);

	// Load Mesh Data
	for (size_t i = 0; i < (m_NbVertices * 3); ++i)
		readvar(File, reinterpret_cast<uint32_t &>(m_VArrays[vertex][i]), 4);

	for (size_t i = 0; i < (m_NbVertices * 3); ++i)
		readvar(File, reinterpret_cast<uint32_t &>(m_VArrays[normal][i]), 4);

	for (size_t i = 0; i < m_NbTextures; ++i)
		for (size_t j = 0; j < (m_NbVertices * 2); ++j)
			readvar(File, reinterpret_cast<uint32_t &>(m_VArrays[array_type(texture_coord0 + i)][j]), 4);

	// Load Each SubMesh
	for (size_t i = 0; i < m_SubMeshes.size(); ++i)
		m_SubMeshes[i].LoadFromVXO(File);
}
开发者ID:jjoonathan,项目名称:objc3d,代码行数:41,代码来源:gl_mesh.cpp

示例7: OTfgets

void OTString::OTfgets(std::istream & ifs)
{
	// _WIN32
	static char * buffer = NULL;
	
	if (NULL == buffer)
	{
		buffer = new char[MAX_STRING_LENGTH]; // This only happens once. Static var.
		OT_ASSERT(NULL != buffer);
	}
	
	buffer[0] = '\0';
	// _end _WIN32
	
	if (ifs.getline(buffer, MAX_STRING_LENGTH-1)) // delimiter defaults to '\n'
	{
		buffer[strlen(buffer)] = '\0';
		
		Set(buffer);
	}	
}
开发者ID:jarlfenrir,项目名称:Open-Transactions,代码行数:21,代码来源:OTString.cpp

示例8: parse

 void SectionParser::parse(std::istream& input, ForceField& ff, int lineNo) {
   const int bufferSize = 65535;
   char buffer[bufferSize];
   std::string line;
   while(input.getline(buffer, bufferSize)) {
     ++lineNo;
     line = trimLeftCopy(buffer);
     //a line begins with "//" is comment
     // let's also call lines starting with # and ! as comments
     if (isEndSection(line)) {
       break;
     } else if ( line.empty() || 
                 (line.size() >= 2 && line[0] == '/' && line[1] == '/') ||
                 (line.size() >= 1 && line[0] == '#') || 
                 (line.size() >= 1 && line[0] == '!') ) {
       continue;
     } else {
       parseLine(ff, line, lineNo);
     }
   }
 }
开发者ID:Patrick-Louden,项目名称:2.2,代码行数:21,代码来源:SectionParser.cpp

示例9: readFuncGroups

  MOL_SPTR_VECT readFuncGroups(std::istream &inStream,int nToRead) {
    MOL_SPTR_VECT funcGroups;
    funcGroups.clear();
    if (inStream.bad()) {
      throw BadFileException("Bad stream contents.");
    }
    const int MAX_LINE_LEN = 512;
    char inLine[MAX_LINE_LEN];
    std::string tmpstr;
    int nRead=0;
    while (!inStream.eof() && (nToRead<0 || nRead<nToRead)) {
      inStream.getline(inLine, MAX_LINE_LEN,'\n');
      tmpstr = inLine;
      // parse the molecule on this line (if there is one)
      ROMol *mol = getSmarts(tmpstr);
      if (mol) {
	funcGroups.push_back(ROMOL_SPTR(mol));
	nRead++;
      }
    }
    return funcGroups;
  }
开发者ID:AlexanderSavelyev,项目名称:rdkit,代码行数:22,代码来源:FragCatalogUtils.cpp

示例10: do_tell

int do_tell(ai::PL::KnowledgeBase &kb, int interactive, char *buf, std::istream &in, std::ostream &out)
{
    char * sentence = 0;
    if(strlen(buf) > 4)
    {
        sentence = &buf[4];
    }
    else
    {
        if(interactive)
        {
            out << "tell> " << std::flush;
        }
        in.getline(buf, BUF_SIZE);
        sentence = buf;
    }
    kb.AddSentence(sentence);
    if(!interactive)
    {
        out << "tell " << sentence << std::endl;
    }
    return 0;
}
开发者ID:sstephens,项目名称:sstephens1,代码行数:23,代码来源:PL_Shell.cpp

示例11: while

void
SimpleConfig::parse_config (std::istream &is, KeyValueRepository &config)
{
    char *conf_line = new char [SCIM_MAX_CONFIG_LINE_LENGTH];

    while (!is.eof()) {
        is.getline(conf_line, SCIM_MAX_CONFIG_LINE_LENGTH);
        if (!is.eof()) {
            String normalized_line = trim_blank(conf_line);

            if ((normalized_line.find_first_of("#") > 0) && (normalized_line.length() != 0)) {
                if (normalized_line.find_first_of("=") == String::npos) {
                    SCIM_DEBUG_CONFIG(2) << " Invalid config line : " << normalized_line << "\n";
                    continue;
                }

                if (normalized_line[0] == '=') {
                    SCIM_DEBUG_CONFIG(2) << " Invalid config line : " << normalized_line << "\n";
                    continue;
                }

                String param = get_param_portion(normalized_line);
                KeyValueRepository::iterator i = config.find(param);

                if (i != config.end()) {
                    SCIM_DEBUG_CONFIG(2) << " Config entry " << normalized_line << " has been read.\n";
                } else {
                    String value = get_value_portion (normalized_line); 
                    config [param] = value;
                    SCIM_DEBUG_CONFIG(2) << " Config entry " << param << "=" << value << " is successfully read.\n";
                }
            }
        }
    }

    delete [] conf_line;
}
开发者ID:Tarnyko,项目名称:dali-isf,代码行数:37,代码来源:scim_simple_config.cpp

示例12: process

void process(const char* filename, std::istream& ifs, std::ostream& ofs, 
    std::ostream& indexfs)
{
    int n = 1024;
    char tmpbuf[1024];
    char tag[128];
    char entry[1024];

    while (!ifs.eof())
    {
        ifs.getline(tmpbuf,n);
        if (ifs.eof())
            break;
        ofs << tmpbuf;

        char* index;
        if ((index = strstr(tmpbuf, "BZINDEX")) != 0) {
            char* index2 = strstr(index, "-->");
            if (index2 != 0)
                index2[-1] = 0;
            index += 8;

            sprintf(tag, "index%05d", tagnum++);
            ofs << "<a name=\"" << tag << "\">";

            makeEntry(entry, index);
            indexfs << index << " |"
                    << entry << "|"
                    << filename << "#" << tag << std::endl;

//            std::cout << "Found tag: \"" << index << "\"" << std::endl;
        }

        ofs << std::endl;
    }
}
开发者ID:blitzpp,项目名称:blitz,代码行数:36,代码来源:makeHTMLIndex.cpp

示例13: LoadObj

std::string LoadObj(
  std::vector<shape_t>& shapes,
  std::vector<material_t>& materials,   // [output]
  std::istream& inStream,
  MaterialReader& readMatFn)
{
  std::stringstream err;

  std::vector<float> v;
  std::vector<float> vn;
  std::vector<float> vt;
  std::vector<std::vector<vertex_index> > faceGroup;
  std::string name;

  // material
  std::map<std::string, int> material_map;
  std::map<vertex_index, unsigned int> vertexCache;
  int  material = -1;

  shape_t shape;

  int maxchars = 8192;  // Alloc enough size.
  std::vector<char> buf(maxchars);  // Alloc enough size.
  while (inStream.peek() != -1) {
    inStream.getline(&buf[0], maxchars);

    std::string linebuf(&buf[0]);

    // Trim newline '\r\n' or '\n'
    if (linebuf.size() > 0) {
      if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1);
    }
    if (linebuf.size() > 0) {
      if (linebuf[linebuf.size()-1] == '\r') linebuf.erase(linebuf.size()-1);
    }

    // Skip if empty line.
    if (linebuf.empty()) {
      continue;
    }

    // Skip leading space.
    const char* token = linebuf.c_str();
    token += strspn(token, " \t");

    assert(token);
    if (token[0] == '\0') continue; // empty line

    if (token[0] == '#') continue;  // comment line

    // vertex
    if (token[0] == 'v' && isSpace((token[1]))) {
      token += 2;
      float x, y, z;
      parseFloat3(x, y, z, token);
      v.push_back(x);
      v.push_back(y);
      v.push_back(z);
      continue;
    }

    // normal
    if (token[0] == 'v' && token[1] == 'n' && isSpace((token[2]))) {
      token += 3;
      float x, y, z;
      parseFloat3(x, y, z, token);
      vn.push_back(x);
      vn.push_back(y);
      vn.push_back(z);
      continue;
    }

    // texcoord
    if (token[0] == 'v' && token[1] == 't' && isSpace((token[2]))) {
      token += 3;
      float x, y;
      parseFloat2(x, y, token);
      vt.push_back(x);
      vt.push_back(y);
      continue;
    }

    // face
    if (token[0] == 'f' && isSpace((token[1]))) {
      token += 2;
      token += strspn(token, " \t");

      std::vector<vertex_index> face;
      while (!isNewLine(token[0])) {
        vertex_index vi = parseTriple(token, v.size() / 3, vn.size() / 3, vt.size() / 2);
        face.push_back(vi);
        int n = strspn(token, " \t\r");
        token += n;
      }

      faceGroup.push_back(face);

      continue;
    }

//.........这里部分代码省略.........
开发者ID:AssociationSirius,项目名称:requiem,代码行数:101,代码来源:tiny_obj_loader.cpp

示例14: LoadMtl

std::string LoadMtl (
  std::map<std::string, int>& material_map,
  std::vector<material_t>& materials,
  std::istream& inStream)
{
  material_map.clear();
  std::stringstream err;

  material_t material;

  int maxchars = 8192;  // Alloc enough size.
  std::vector<char> buf(maxchars);  // Alloc enough size.
  while (inStream.peek() != -1) {
    inStream.getline(&buf[0], maxchars);

    std::string linebuf(&buf[0]);

    // Trim newline '\r\n' or '\n'
    if (linebuf.size() > 0) {
      if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1);
    }
    if (linebuf.size() > 0) {
      if (linebuf[linebuf.size()-1] == '\r') linebuf.erase(linebuf.size()-1);
    }

    // Skip if empty line.
    if (linebuf.empty()) {
      continue;
    }

    // Skip leading space.
    const char* token = linebuf.c_str();
    token += strspn(token, " \t");

    assert(token);
    if (token[0] == '\0') continue; // empty line

    if (token[0] == '#') continue;  // comment line

    // new mtl
    if ((0 == strncmp(token, "newmtl", 6)) && isSpace((token[6]))) {
      // flush previous material.
      if (!material.name.empty())
      {
          material_map.insert(std::pair<std::string, int>(material.name, materials.size()));
          materials.push_back(material);
      }

      // initial temporary material
      InitMaterial(material);

      // set new mtl name
      char namebuf[4096];
      token += 7;
      sscanf(token, "%s", namebuf);
      material.name = namebuf;
      continue;
    }

    // ambient
    if (token[0] == 'K' && token[1] == 'a' && isSpace((token[2]))) {
      token += 2;
      float r, g, b;
      parseFloat3(r, g, b, token);
      material.ambient[0] = r;
      material.ambient[1] = g;
      material.ambient[2] = b;
      continue;
    }

    // diffuse
    if (token[0] == 'K' && token[1] == 'd' && isSpace((token[2]))) {
      token += 2;
      float r, g, b;
      parseFloat3(r, g, b, token);
      material.diffuse[0] = r;
      material.diffuse[1] = g;
      material.diffuse[2] = b;
      continue;
    }

    // specular
    if (token[0] == 'K' && token[1] == 's' && isSpace((token[2]))) {
      token += 2;
      float r, g, b;
      parseFloat3(r, g, b, token);
      material.specular[0] = r;
      material.specular[1] = g;
      material.specular[2] = b;
      continue;
    }

    // transmittance
    if (token[0] == 'K' && token[1] == 't' && isSpace((token[2]))) {
      token += 2;
      float r, g, b;
      parseFloat3(r, g, b, token);
      material.transmittance[0] = r;
      material.transmittance[1] = g;
      material.transmittance[2] = b;
//.........这里部分代码省略.........
开发者ID:AssociationSirius,项目名称:requiem,代码行数:101,代码来源:tiny_obj_loader.cpp

示例15: createILF

unsigned int ilf::createILF( std::istream &infile, std::ofstream &outfile )
{
    unsigned int total = 0;
    char temp[512];

    // Write form with dummy size
    unsigned int form0Position = outfile.tellp();
    writeFormHeader( outfile, 0, "INLY" );
    // Write form with dummy size
    unsigned int form1Position = outfile.tellp();
    writeFormHeader( outfile, 0, "0000" );

    while( !infile.eof() )
    {
	unsigned int nodeSize = 0;

	infile.getline( temp, 512, ':' );
	if( infile.eof() ) { break; };
	std::string objectFilename;
	infile >> objectFilename;
	std::cout << objectFilename << std::endl;
	nodeSize += static_cast<unsigned int>( objectFilename.size() + 1 );

	infile.getline( temp, 512, ':' );
	std::string objectZone;
	infile >> objectZone;
	std::cout << objectZone << std::endl;
	nodeSize += static_cast<unsigned int>( objectZone.size() + 1 );

	// 'Transform matrix:' line
	infile.getline( temp, 512, ':' );

	std::cout.flags ( std::ios_base::showpoint );
	std::cout << std::dec;
	std::cout.flags( std::ios_base::fixed );
	float x[12];
	for( unsigned int i = 0; i < 12; ++i )
	{
	    std::cout.width( 10 );
	    infile >> x[i];
	    nodeSize += sizeof( float );
	    std::cout << x[i] << " ";
	}
	std::cout << std::endl;

	// Blank line
	infile.getline( temp, 512 );

	total += writeRecordHeader( outfile, "NODE", nodeSize );
	outfile.write( objectFilename.c_str(),
		       static_cast<unsigned int>( objectFilename.size()+1 )
	    );
	outfile.write( objectZone.c_str(),
		       static_cast<unsigned int>( objectZone.size()+1 )
	    );
	outfile.write( (char*)x, sizeof( float ) * 12 );
	total += nodeSize;
    }

    // Rewrite form with proper size.
    outfile.seekp( form1Position, std::ios_base::beg );
    total += writeFormHeader( outfile, total+4, "0000" );

    // Rewrite form with proper size.
    outfile.seekp( form0Position, std::ios_base::beg );
    total += writeFormHeader( outfile, total+4, "INLY" );

    return total;
}
开发者ID:Mesagoppinmypants,项目名称:Tools,代码行数:69,代码来源:ilf.cpp


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