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


C++ string::resize方法代码示例

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


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

示例1: utf8truncate

void utf8truncate(std::string& utf8str, size_t len)
{
    try
    {
        size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
        if (wlen <= len)
            return;

        std::wstring wstr;
        wstr.resize(wlen);
        utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), &wstr[0]);
        wstr.resize(len);
        char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str() + wstr.size(), &utf8str[0]);
        utf8str.resize(oend - (&utf8str[0]));               // remove unused tail
    }
    catch (std::exception)
    {
        utf8str = "";
    }
}
开发者ID:Astoz,项目名称:mangos-wotlk,代码行数:20,代码来源:Util.cpp

示例2: send_response

void send_response(newsflash::native_socket_t sock, std::string resp, bool print = true)
{
    resp.append("\r\n");
    int sent = 0;
    do 
    {
        const char* ptr = resp.data() + sent;
        const auto len  = resp.size() - sent;
        const auto bytes = ::send(sock, ptr, len, 0);
        if (bytes < 0)
            throw std::runtime_error("socket send error");
        sent += bytes;
    } while(sent != resp.size());

    if (print)
    {
        resp.resize(resp.size() - 2);
        std::cout << "< " << resp << std::endl;
    }
}
开发者ID:ensisoft,项目名称:newsflash-plus,代码行数:20,代码来源:server.cpp

示例3: GetField

bool GetField(std::istream &is, std::string &name, std::string &value)
{
	name.resize(0);		// GCC workaround: 2.95.3 doesn't have clear()
	is >> name;

#if defined(__COVERITY__)
	// The datafile being read is in /usr/share, and it protected by filesystem ACLs
	// __coverity_tainted_data_sanitize__(reinterpret_cast<void*>(&name));
#endif

	if (name.empty())
		return false;

	if (name[name.size()-1] != ':')
	{
		char c;
		is >> skipws >> c;
		if (c != ':')
			SignalTestError();
	}
开发者ID:CryptoDJ,项目名称:DarkSilk-Release-Candidate,代码行数:20,代码来源:datatest.cpp

示例4:

float
FoldingEngine<SEQ>::
decode_structure(float gamma, std::string& paren) const
{
  float p=0.0;
  paren.resize(bp_.size());
  std::fill(paren.begin(), paren.end(), '.');
  if (!mea_) {
    if (max_bp_dist_==0)
      p = Centroid::execute(bp_, paren, gamma);
    else
      p = Centroid::execute(bp_, paren, max_bp_dist_, gamma);
  } else {
    if (max_bp_dist_==0)
      p = MEA::execute(bp_, paren, gamma);
    else
      p = MEA::execute(bp_, paren, max_bp_dist_, gamma);
  }
  return p;
}
开发者ID:TakashiMatsuda,项目名称:ractIP_alifold,代码行数:20,代码来源:folding_engine.cpp

示例5: GetTextDirection

TextDirection GetTextDirection( std::string locale )
{
  TextDirection direction( LeftToRight );

  if ( !locale.empty() && locale.size() > 2 )
  {
    // We're only interested in the first two characters
    locale.resize(2);

    for ( const LocaleDirection* iter = &LOCALE_DIRECTION_LOOKUP_TABLE[0]; iter->locale; ++iter )
    {
      if ( !locale.compare( iter->locale ) )
      {
        direction = iter->direction;
        break;
      }
    }
  }

  return direction;
}
开发者ID:Tarnyko,项目名称:dali-adaptor,代码行数:21,代码来源:locale-utils.cpp

示例6: servlist_check_encoding

/* check if a charset is known by Iconv */
bool servlist_check_encoding(std::string charset)
{
	auto space = charset.find_first_of(' ');
	if (space != std::string::npos)
		charset.resize(space);

	if (!g_ascii_strcasecmp (charset.c_str(), "IRC")) /* special case */
	{
		return true;
	}

	auto gic = g_iconv_open (charset.c_str(), "UTF-8");

	if (gic != (GIConv)-1)
	{
		g_iconv_close (gic);
		return true;
	}

	return false;
}
开发者ID:leeter,项目名称:hexchat,代码行数:22,代码来源:servlist.cpp

示例7: memcpy

const std::string & Parser::_getNextToken(unsigned int & fromPosition)
{
   fromPosition = _skipWhiteSpacesFromContent(fromPosition);
   unsigned int position = _fileContent.find_first_of(WHITESPACES, fromPosition);

   static std::string token;
   if(position > fromPosition)
   {        
      unsigned int tokenSize = position - fromPosition;
      token.resize(tokenSize);
      memcpy(&token[0], &_fileContent[fromPosition], tokenSize);
      fromPosition = position;
      return token;
   }
   else
   {
      //TODO throw exception
   }
   token = "";
   return token;
}
开发者ID:KubaO,项目名称:Sankore-3.1,代码行数:21,代码来源:Parser.cpp

示例8: LoadTextFileToExistingString

///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool LoadTextFileToExistingString( const std::string& filePath, std::string& existingString )
{
    FILE* file;
    fopen_s( &file, filePath.c_str(), "rb" );

    if (!file)
    {
        // freak out
        return false;
    }

    size_t neededStringSize = GetFileLength( file );

    // Grow/shrink
    existingString.resize( neededStringSize );
    fread( (void*)existingString.data(), sizeof( unsigned char ), neededStringSize, file );

    fclose( file );
    return true;

}
开发者ID:tbgeorge,项目名称:putty_engine,代码行数:24,代码来源:FileUtilities.cpp

示例9: GetSerialNumber

// HINT: This information remains static throughout the object's lifetime
inline VmbErrorType Interface::GetSerialNumber( std::string &rStrSerial ) const
{
    VmbErrorType res;
    VmbUint32_t nLength;

    res = GetSerialNumber( NULL, nLength );
    if ( VmbErrorSuccess == res )
    {
        if ( 0 < nLength )
        {
            rStrSerial.resize( nLength );
            res = GetSerialNumber( &rStrSerial[0], nLength );
        }
        else
        {
            rStrSerial.clear();
        }
    }

    return res;
}
开发者ID:SanderGrielens,项目名称:rapido,代码行数:22,代码来源:Interface.hpp

示例10: removeTrailingZeros

void removeTrailingZeros(std::string& s)
{
	if(s.find('.') != std::string::npos)
	{
		size_t newLength = s.size() - 1;
		while(s[newLength] == '0')
		{
			newLength--;
		}

		if(s[newLength] == '.')
		{
			newLength--;
		}

		if(newLength != s.size() - 1)
		{
			s.resize(newLength + 1);
		}
	}
}
开发者ID:asakul,项目名称:goldmine-quik-gateway,代码行数:21,代码来源:quikbroker.cpp

示例11: ReadString

bool SpFileReader::ReadString(std::string &Str)
{
    /* Read string length */
    uint32 Len = Read<uint32>();
    
    if (Len == 0)
    {
        Str = "";
        return true;
    }
    
    /* Check if string is too long */
    if (Len + GetPosition() >= Size_)
        return false;
    
    /* Read string characters */
    Str.resize(Len);
    Read(&Str[0], Len);
    
    return true;
}
开发者ID:bekasov,项目名称:SoftPixelEngine,代码行数:21,代码来源:spsFileReader.cpp

示例12: GetName

// HINT: This information remains static throughout the object's lifetime
inline VmbErrorType Interface::GetName( std::string &rStrName ) const
{
    VmbErrorType res;
    VmbUint32_t nLength;

    res = GetName( NULL, nLength );
    if ( VmbErrorSuccess == res )
    {
        if ( 0 < nLength )
        {
            rStrName.resize( nLength );
            res = GetName( &rStrName[0], nLength );
        }
        else
        {
            rStrName.clear();
        }
    }

    return res;
}
开发者ID:SanderGrielens,项目名称:rapido,代码行数:22,代码来源:Interface.hpp

示例13: getFileContent

bool QIO::getFileContent(std::string fileName, std::string &content)
{
    std::ifstream file(fileName.c_str());
    if (!file)
    {
        std::cerr << " > ERROR: unable to open input file: \"" << fileName << "\"." <<  std::endl;
        return false;
    }
    
    file.seekg(0, std::ios::end);
    int length = file.tellg();
    file.seekg(0, std::ios::beg);
    
    // content.reserve(length);
    // content.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
    content.resize(length);
    file.read((char*)content.data(), length);
    file.close();
    
    return true;
}
开发者ID:15pengyi,项目名称:JF-Cut,代码行数:21,代码来源:QIO.cpp

示例14: readStringFromPatternsFile

// ----------------------------------------------------------------------------------------------
// returns false if couldn't read a string containing at least one char
bool EDITOR::readStringFromPatternsFile(EMUFILE *is, std::string& dest)
{
	dest.resize(0);
	int charr;
	while (true)
	{
		charr = is->fgetc();
		if (charr < 0) break;
		if (charr == 10 || charr == 13)		// end of line
		{
			if (dest.size())
				break;		// already collected at least one char
			else
				continue;	// skip the char and continue searching
		} else
		{
			dest.push_back(charr);
		}
	}
	return dest.size() != 0;
}
开发者ID:CharlexH,项目名称:Provenance,代码行数:23,代码来源:editor.cpp

示例15: hashTag

/*!
 * \brief Receive message from a specific node rank via MPI
 * \param outMessage Message receive.
 * \param inTag Tag associated to the message to be received.
 * \param inRank Node rank of the sending node.
 */
void HPC::MPICommunication::receive(std::string& outMessage, const std::string& inTag, int inRank) const
{
	Beagle_StackTraceBeginM();
	MPI::Status lStatus;

	int lSize = 0;
	MPI::COMM_WORLD.Recv(&lSize, 1, MPI::INT, inRank, hashTag(inTag+"_size"));
	MPI::COMM_WORLD.Probe(inRank,hashTag(inTag+"_str"),lStatus);
	Beagle_AssertM(lStatus.Get_count(MPI::CHAR) == lSize);
	outMessage.resize(lSize);
	MPI::COMM_WORLD.Recv(&outMessage[0], lSize, MPI::CHAR, lStatus.Get_source(), hashTag(inTag+"_str"));

#ifdef BEAGLE_HAVE_LIBZ
	if(mCompressionLevel->getWrappedValue() > 0){
		std::string lString;
		decompressString(outMessage, lString);
		outMessage = lString;
	}
#endif
	Beagle_HPC_StackTraceEndM("void HPC::MPICommunication::receive(std::string&, const std::string&, int) const");
}
开发者ID:GhostGambler,项目名称:beagle,代码行数:27,代码来源:MPICommunication.cpp


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