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


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

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


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

示例1: read_file_data_ex

/// Read data and add terminating 0
void fsutil::read_file_data_ex(const char *filename, std::string& data, size_t align)
{
    // Open stream
    std::ifstream stream(filename, std::ios::binary);
    if (!stream)
        throw std::runtime_error(std::string("cannot open file ") + filename);
    stream.unsetf(std::ios::skipws);

    // Determine stream size
    stream.seekg(0, std::ios::end);
    size_t size = stream.tellg();
    stream.seekg(0);   

    // Calc Padding size
    size_t padding_size = 0;
    if(align > 0)
        padding_size = align - size % align;

    // Load data
    data.resize(size + padding_size + 1);
    stream.read(&data.front(), static_cast<std::streamsize>(size));

    // Padding data
    for(size_t offst = 0; offst < padding_size; ++offst) 
    {
        *(&data.front() + size + offst) = padding_size;
    }

    //  And add terminating
    data[size] = 0;
}
开发者ID:xubingyue,项目名称:libxstudio365,代码行数:32,代码来源:xxfsutility.cpp

示例2: toNum

long long toNum(std::string str, int type = 0)
{
	int len = str.length();
	long long ret = 0;
	if (len < 1)
		return 0;
	if (canBeNum(str) == false)
		return 0;
	std::stringstream ss;
	bool negative = false;
	if (str.front() == '-')
	{
		str.erase(0, 1);
		negative = true;
		len--;
	}
	else if (str.front() == '+')
	{
		str.erase(0, 1);
		len--;
	}
	switch (type)
	{
		case 0:
			if (len == 0)
				return 0;
			if (str.back() == 'h' || str.back() == 'H')
			{
				str.erase(len - 1, 1);
				ss << std::hex << str;
				ss >> ret;
			}
			else if (str.front() == '0' && len > 1)
开发者ID:xy12423,项目名称:xy_DCPU16_Emulator,代码行数:33,代码来源:function.hpp

示例3: zusiPfadZuOsPfad

        std::string zusiPfadZuOsPfad(const std::string& zusiPfad, const std::string& osPfadUebergeordnet) {
            std::string result;
            if (zusiPfad.find('\\') == zusiPfad.npos && !osPfadUebergeordnet.empty()) {
                // Relativ zu uebergeordnetem Pfad
                if (zusiPfad.empty()) {
                    return osPfadUebergeordnet;
                }
                result = osPfadUebergeordnet.substr(0, osPfadUebergeordnet.rfind('/'));
            } else {
                // Relativ zum Zusi-Datenverzeichnis
                result = getZusi3Datenpfad();
                if (result.empty()) {
                    return "";
                }
            }

            if (result.back() == '\\' && zusiPfad.front() == '\\') {
                result.pop_back();
            } else if (result.back() != '\\' && zusiPfad.front() != '\\') {
                result.push_back('\\');
            }

            result += zusiPfad;
            return result;
        }
开发者ID:zusitools,项目名称:zusi_file_lib,代码行数:25,代码来源:pfade_win.hpp

示例4: ler_comando

void ler_comando(std::string c, ABB &arv) {
	std::string aux;
	int x;
	while (!c.empty()){
		if(c.front() == ' ') {
        	c.erase(0,1);
        	break;
        }
        else{
            aux = aux + c.front();
            c.erase(0,1);
        }
    }

    if (!c.empty()) {
    	x = std::stoi (c, nullptr, 10);
    }

    if (aux == "ENESIMO") {
    	std::cout << "O elemento na " << x << "ª posicao eh o: " << arv.enesimoElemento(x) << std::endl;
    }

    else if (aux == "POSICAO") {
    	std::cout << "O elemento " << x << " esta na " << arv.posicao(x) << "ª posicao" << std::endl;
    }


    else if (aux == "MEDIANA") {
    	std::cout << "A mediana da ABB eh o elemento: " << arv.mediana() << std::endl;
    }

    else if (aux == "CHEIA") {
    	if (arv.ehCheia()) {
    		std::cout << "A ABB eh cheia!" << std::endl;
    	}
    	
    	else
    		std::cout << "A ABB Nao eh cheia! " << std::endl;
    }

    else if (aux == "COMPLETA") {
    	if (arv.ehCompleta()) {
			std::cout << "A ABB eh completa!" << std::endl;
    	}

    	else 
    		std::cout << "A ABB nao eh completa!" << std::endl;
    }

    else if (aux == "IMPRIMA") {
    	std::cout << "Imprimindo ABB por nivel: " << arv.toString() << std::endl;
    }

    else if (aux == "REMOVA") {
    	std::cout << "Removendo o elemento: " << x << " ..." << std::endl;
    	arv.remocao(x);
    }

}
开发者ID:giovannirosario,项目名称:ABB,代码行数:59,代码来源:main.cpp

示例5: isSourceName

/// Test if a name (parameter's or attribute's) belongs to m_source
/// @param aName :: A name to test.
bool FunctionGenerator::isSourceName(const std::string &aName) const {
    if (aName.empty()) {
        throw std::invalid_argument(
            "Parameter or attribute name cannot be empty string.");
    }
    return (aName.front() != 'f' || aName.find('.') == std::string::npos);
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:9,代码来源:FunctionGenerator.cpp

示例6: query

URL::URL(const std::string& str)
    : query([&]() -> Segment {
          const auto hashPos = str.find('#');
          const auto queryPos = str.find('?');
          if (queryPos == std::string::npos || hashPos < queryPos) {
              return { hashPos != std::string::npos ? hashPos : str.size(), 0 };
          }
          return { queryPos, (hashPos != std::string::npos ? hashPos : str.size()) - queryPos };
      }()),
      scheme([&]() -> Segment {
          if (str.empty() || !isAlphaCharacter(str.front())) return { 0, 0 };
          size_t schemeEnd = 0;
          while (schemeEnd < query.first && isSchemeCharacter(str[schemeEnd])) ++schemeEnd;
          return { 0, str[schemeEnd] == ':' ? schemeEnd : 0 };
      }()),
      domain([&]() -> Segment {
          auto domainPos = scheme.first + scheme.second;
          while (domainPos < query.first && (str[domainPos] == ':' || str[domainPos] == '/')) {
              ++domainPos;
          }
          const bool isData = str.compare(scheme.first, scheme.second, "data") == 0;
          const auto endPos = str.find(isData ? ',' : '/', domainPos);
          return { domainPos, std::min(query.first, endPos) - domainPos };
      }()),
      path([&]() -> Segment {
          auto pathPos = domain.first + domain.second;
          const bool isData = str.compare(scheme.first, scheme.second, "data") == 0;
          if (isData) {
              // Skip comma
              pathPos++;
          }
          return { pathPos, query.first - pathPos };
      }()) {
}
开发者ID:1SpatialGroupLtd,项目名称:mapbox-gl-native,代码行数:34,代码来源:url.cpp

示例7: EdifyToken

EdifyTokenString::EdifyTokenString(std::string str, Type type)
    : EdifyToken(EdifyTokenType::String), m_type(type)
{
    switch (type) {
    case AlreadyQuoted:
        m_quoted = true;
        assert(str.size() >= 2);
        assert(str.front() == '"');
        assert(str.back() == '"');
        m_str = std::move(str);
        break;
    case NotQuoted:
        m_quoted = false;
        m_str = std::move(str);
        break;
    case MakeQuoted:
        m_quoted = true;
        std::string temp;
        escape(str, &temp);
        temp.insert(temp.begin(), '"');
        temp.push_back('"');
        m_str = std::move(str);
        break;
    }
}
开发者ID:Ricky310711,项目名称:DualBootPatcher,代码行数:25,代码来源:tokenizer.cpp

示例8: countWays

 int countWays(std::string s) {
   if (s=="") return 1;
   if (memo.count(s)) return memo[s];
   
   assert(s.front()=='(');
   int N=SZ(s), res=0, d=0;
   REP(i,N) {
     if (s[i]=='(') {
       ++d; continue;
     }
     
     --d;
     string t;
     if (i==N-1) {
       t = s.substr(1,i-1);
     } else {
       t = s.substr(1,i-1) + s.substr(min(N-1,i+1));
     }
     
     res += countWays(t);
     
     if (d==0) break;
   }
   
   return memo[s] = res;
 }
开发者ID:k-ori,项目名称:topcoder-offline,代码行数:26,代码来源:RemovingParenthesis.cpp

示例9: if

static std::string repeat(std::string str, size_t n)
{
	if(n == 0)
	{
		str.clear();
		str.shrink_to_fit();
		return str;
	}
	else if(n == 1 || str.empty())
	{
		return str;
	}

	auto period = str.size();
	if(period == 1)
	{
		str.append(n - 1, str.front());
		return str;
	}

	str.reserve(period * n);
	size_t m = 2;
	for(; m < n; m *= 2)
		str += str;

	str.append(str.c_str(), (n - (m / 2)) * period);

	return str;
}
开发者ID:flax-lang,项目名称:flax,代码行数:29,代码来源:errors.cpp

示例10: PluginPath

Pothos::BlockRegistry::BlockRegistry(const std::string &path, const Callable &factory)
{
    //check the path
    if (path.empty() or path.front() != '/')
    {
        poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Invalid path: %s", path);
        return;
    }

    //parse the path
    PluginPath fullPath;
    try
    {
        fullPath = PluginPath("/blocks").join(path.substr(1));
    }
    catch (const PluginPathError &)
    {
        poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Invalid path: %s", path);
        return;
    }

    //check the factory
    if (factory.type(-1) == typeid(Block*) or factory.type(-1) == typeid(Topology*))
    {
        //register
        PluginRegistry::add(fullPath, factory);
    }

    //otherwise report the error
    else
    {
        poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Bad Factory, must return Block* or Topology*: %s", factory.toString());
    }
}
开发者ID:hailynch,项目名称:pothos,代码行数:34,代码来源:BlockRegistry.cpp

示例11: ReadAttribute

 void ReadAttribute(char c)
 {
     if (buffer.empty())
     {
         if (!IsWhitespace(c))
         {
             if (c == '"' || c == '\'')
                 Store(c);
             else
             {
                 state = State::SkipTag;
             }
         }
     }
     else if (c == buffer.front())
     {
         StoreLink();
         ClearBuffer();
         state = State::SkipTag;
     }
     else
     {
         Store(c);
     }
 }
开发者ID:hansmaad,项目名称:Chase,代码行数:25,代码来源:HtmlSearch.cpp

示例12: getOutputString

std::string getOutputString(std::string numberString) {
	std::string lineString { };

	if (numberString.size() && numberString.front() == '-')
		numberString.front() = digitOffset + 10;

	addSpace(numberString);

	for (unsigned int i = 0; i < allDigits[0].size(); i++) {
		for (char c : numberString) {
			lineString += allDigits[c - digitOffset][i] + " ";
		}
		lineString += "\n";
	}
	return lineString;
}
开发者ID:asta1992,项目名称:CPlusPlus,代码行数:16,代码来源:sevensegment.cpp

示例13: SaveToFile

bool SaveToFile(const std::string& data, const std::wstring& path,
                bool take_backup) {
  if (data.empty())
    return false;

  return SaveToFile((LPCVOID)&data.front(), data.size(), path, take_backup);
}
开发者ID:Hydro8182,项目名称:taiga,代码行数:7,代码来源:file.cpp

示例14: ReadEntry

void vfsHDD::ReadEntry(u64 block, std::string& name)
{
	CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) != -1);
	
	name.resize(GetMaxNameLen());
	m_hdd_file.Read(&name.front(), GetMaxNameLen());
}
开发者ID:ss23,项目名称:rpcs3,代码行数:7,代码来源:HDD.cpp

示例15: readInternal

 void readInternal(std::string& value)
 {
     size_t size;
     visit(size);
     value.resize(size);
     mStore.read(&value.front(), size);
 }
开发者ID:hallor,项目名称:vasum,代码行数:7,代码来源:from-fdstore-visitor-base.hpp


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