本文整理汇总了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;
}
示例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)
示例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;
}
示例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);
}
}
示例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);
}
示例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 };
}()) {
}
示例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;
}
}
示例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;
}
示例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;
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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());
}
示例15: readInternal
void readInternal(std::string& value)
{
size_t size;
visit(size);
value.resize(size);
mStore.read(&value.front(), size);
}