本文整理汇总了C++中std::string::pop_back方法的典型用法代码示例。如果您正苦于以下问题:C++ string::pop_back方法的具体用法?C++ string::pop_back怎么用?C++ string::pop_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::pop_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_db_users
void write_db_users()
{
m_write_db_users_time = srv_time();
if (!m_use_sql)
return;
if (!m_torrents_users_updates_buffer.empty())
{
m_torrents_users_updates_buffer.pop_back();
async_query("insert into " + db_name("files_users") + " (active, announced, completed, downloaded, `left`, uploaded, mtime, fid, uid) values "
+ m_torrents_users_updates_buffer
+ " on duplicate key update"
+ " active = values(active),"
+ " announced = announced + values(announced),"
+ " completed = completed + values(completed),"
+ " downloaded = downloaded + values(downloaded),"
+ " `left` = values(`left`),"
+ " uploaded = uploaded + values(uploaded),"
+ " mtime = values(mtime)");
m_torrents_users_updates_buffer.erase();
}
async_query("update " + db_name("files_users") + " set active = 0 where mtime < unix_timestamp() - 60 * 60");
if (!m_users_updates_buffer.empty())
{
m_users_updates_buffer.pop_back();
async_query("insert into " + db_name("users") + " (downloaded, uploaded, " + db_name("uid") + ") values "
+ m_users_updates_buffer
+ " on duplicate key update"
+ " downloaded = downloaded + values(downloaded),"
+ " uploaded = uploaded + values(uploaded)");
m_users_updates_buffer.erase();
}
}
示例2: parse_obj
bool ConfigReader::parse_obj(const std::string &key, std::string &obj,
std::string &err)
{
std::vector<std::string> items;
std::string okey, oval;
std::unordered_map<std::string, std::string> map;
size_t ind;
/* remove surrounding braces and whitespace */
obj = obj.substr(1);
remove_leading(obj);
while (obj.back() != '}')
obj.pop_back();
obj.pop_back();
while (isspace(obj.back()))
obj.pop_back();
utils::split(obj, '\n', items);
for (std::string s : items) {
if ((ind = s.find('=')) == std::string::npos) {
err = "unrecognized token in list -- ";
for (ind = 0; !isspace(s[ind]); ++ind)
err += s[ind];
return false;
}
okey = s.substr(0, ind);
while (isspace(okey.back()))
okey.pop_back();
oval = parse_string(s);
map[okey] = oval;
}
olistmap[key].emplace_back(map);
return true;
}
示例3: generate
void generate(int l, int r)
{
if (l == 0)
{
for (int i = 0; i < r; ++i)
{
_s.push_back(')');
}
_res.push_back(_s);
for (int i = 0; i < r; ++i)
{
_s.pop_back();
}
return ;
}
_s.push_back('(');
generate(l-1, r);
_s.pop_back();
if (!_s.empty() && l < r)
{
_s.push_back(')');
generate(l, r-1);
_s.pop_back();
}
}
示例4: Validate
bool CreditCard::Validate(std::string creditCardNumber)
{
unsigned int sum=0;
bool toggle=true;
unsigned int otherCheckDigit=creditCardNumber.back() - '0';
unsigned int myCheckDigit=0;
creditCardNumber.pop_back();
while(!creditCardNumber.empty())
{
unsigned int temp=creditCardNumber.back() - '0'; //saves last digit
if (toggle)
{
temp= temp*2;
if (temp>=10)
temp=temp-9;
}
sum=sum+temp;
toggle=!toggle;
creditCardNumber.pop_back(); //deletes last digit
}
myCheckDigit= (sum*9)%10;
return (otherCheckDigit==myCheckDigit);
}
示例5: receive
bool GenericSocket::receive(int timeout, std::string &reply, int expected, bool raw)
{
int length;
int run;
struct pollfd pfd = { .fd = fd, .events = POLLIN | POLLERR | POLLHUP, .revents = 0 };
char buffer[8192];
reply.clear();
for(run = 8; run > 0; run--)
{
if(poll(&pfd, 1, timeout) != 1)
return(false);
if(pfd.revents & (POLLERR | POLLHUP))
return(false);
if((length = read(fd, buffer, sizeof(buffer) - 1)) < 0)
return(false);
if(length == 0)
{
if(reply.length() == 0) // ignore terminating empty udp packed from previous output
continue;
else
break;
}
reply.append(buffer, (size_t)length);
if((expected > 0) && (expected > length))
expected -= length;
else
break;
}
if(reply.back() == '\n')
reply.pop_back();
if(!raw && (reply.back() == '\r'))
reply.pop_back();
return(true);
}
static std::string sha_hash_to_text(const unsigned char *hash)
{
unsigned int current;
std::stringstream hash_string;
for(current = 0; current < SHA_DIGEST_LENGTH; current++)
hash_string << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)hash[current];
return(hash_string.str());
}
示例6: write_db_torrents
void write_db_torrents()
{
m_write_db_torrents_time = srv_time();
if (!m_use_sql)
return;
try
{
std::string buffer;
while (1)
{
for (auto& i : m_torrents)
{
t_torrent& file = i.second;
if (!file.dirty)
continue;
if (!file.fid)
{
Csql_query(m_database, "insert into @files (info_hash, mtime, ctime) values (?, unix_timestamp(), unix_timestamp())")(i.first).execute();
file.fid = m_database.insert_id();
}
buffer += Csql_query(m_database, "(?,?,?,?),")(file.leechers)(file.seeders)(file.completed)(file.fid).read();
file.dirty = false;
if (buffer.size() > 255 << 10)
break;
}
if (buffer.empty())
break;
buffer.pop_back();
async_query("insert into " + db_name("files") + " (" + db_name("leechers") + ", " + db_name("seeders") + ", " + db_name("completed") + ", " + db_name("fid") + ") values "
+ buffer
+ " on duplicate key update"
+ " " + db_name("leechers") + " = values(" + db_name("leechers") + "),"
+ " " + db_name("seeders") + " = values(" + db_name("seeders") + "),"
+ " " + db_name("completed") + " = values(" + db_name("completed") + "),"
+ " mtime = unix_timestamp()");
buffer.clear();
}
}
catch (bad_query&)
{
}
if (!m_announce_log_buffer.empty())
{
m_announce_log_buffer.pop_back();
async_query("insert delayed into " + db_name("announce_log") + " (ipa, port, event, info_hash, peer_id, downloaded, left0, uploaded, uid, mtime) values " + m_announce_log_buffer);
m_announce_log_buffer.erase();
}
if (!m_scrape_log_buffer.empty())
{
m_scrape_log_buffer.pop_back();
async_query("insert delayed into " + db_name("scrape_log") + " (ipa, uid, mtime) values " + m_scrape_log_buffer);
m_scrape_log_buffer.erase();
}
}
示例7: get_path
std::string get_path(std::string f) {
while (true) {
if (f.empty())
throw exception("failed to locate Lean executable location");
if (f.back() == g_sep) {
f.pop_back();
return f;
}
f.pop_back();
}
}
示例8: SplitGltfAttribute
void SplitGltfAttribute(std::string attribute, std::string *semanticName, DWORD *semanticIndex)
{
*semanticIndex = 0;
if (isdigit(attribute.back()))
{
*semanticIndex = attribute.back() - '0';
attribute.pop_back();
if (attribute.back() == '_')
attribute.pop_back();
}
*semanticName = attribute;
}
示例9: if
LogLevel
Logging::findLevel(std::string mn) const
{
while (!mn.empty()) {
auto it = m_enabledLevel.find(mn);
if (it != m_enabledLevel.end()) {
return it->second;
}
size_t pos = mn.find_last_of('.');
if (pos < mn.size() - 1) {
mn = mn.substr(0, pos + 1);
}
else if (pos == mn.size() - 1) {
mn.pop_back();
pos = mn.find_last_of('.');
if (pos != std::string::npos) {
mn = mn.substr(0, pos + 1);
}
else {
mn = "";
}
}
else {
mn = "";
}
}
auto it = m_enabledLevel.find(mn);
return it != m_enabledLevel.end() ? it->second : INITIAL_DEFAULT_LEVEL;
}
示例10: on_key
void on_key(dick::Key key, bool down) override
{
if (!down) {
return;
}
if (key >= dick::Key::A && key <= dick::Key::Z) {
m_name.push_back(
static_cast<int>(key) -
static_cast<int>(dick::Key::A) +
'A');
} else if (key == dick::Key::SPACE) {
m_name.push_back(' ');
} else if (key == dick::Key::BACKSPACE && !m_name.empty()) {
m_name.pop_back();
} else if (key == dick::Key::ENTER) {
m_high_score.add_entry(
m_context->m_var.m_ball_count,
{ m_context->m_var.m_score, m_name });
HighScore::store("high_score", m_high_score);
t_transition_required = true;
}
}
示例11: giveRawLineFromInput
bool
OOFEMTXTDataReader :: giveRawLineFromInput(std :: ifstream &stream, int &lineNum, std :: string &line)
{
//
// reads one line from inputStream - for private use only.
//
do {
lineNum++;
std :: getline(stream, line);
if ( !stream ) {
return false;
} if ( line.length() > 0 ) {
if ( line.back() == '\\' ) {
std :: string continuedLine;
do {
lineNum++;
std :: getline(stream, continuedLine);
if ( !stream ) {
return false;
}
line.pop_back();
line += continuedLine;
} while ( continuedLine.back() == '\\' );
}
}
} while ( line.length() == 0 || line [ 0 ] == '#' ); // skip comments
return true;
}
示例12: unpack
void unpack(std::vector<std::string>& leftcol, std::vector<std::string>& rightcol, std::vector<std::string> origv, std::string perm)
{
std::string tempstring, leftval, rightval;
std::vector<std::string> tempvec;
int count = 0;
while(std::find(origv.begin(), origv.end(), perm) == origv.end()) {
tempvec = split(perm);
perm = "";
tempstring = tempvec.back();
tempvec.pop_back();
tempvec.insert(tempvec.begin(), tempstring);
for(const auto &ref:tempvec)
perm += ref + " ";
perm.pop_back();
count++;
}
if(count != 0) {
for(int i = 0; i < tempvec.size(); i++) {
if(i < count) {
leftval += tempvec[i] + " ";
}
else {
rightval += tempvec[i] + " ";
}
}
leftval.pop_back();
rightval.pop_back();
leftcol.push_back(leftval);
rightcol.push_back(rightval);
}
else {
leftcol.push_back(" ");
rightcol.push_back(perm);
}
}
示例13: tmp
BigNumber& BigNumber::operator*= (const BigNumber& rhs)
{
BigNumber tmp(*this);
if (is_negative ^ rhs.is_negative) {
is_negative = true;
}
number = number + std::string(rhs.number.size(), 0);
for(auto &c: number) {
c = 0;
}
int carry = 0;
for (int i = 0; i < tmp.number.size(); ++i) {
carry = 0;
for (int j =0; j < rhs.number.size() || carry; ++j) {
int new_digit = number[i+j] + carry;
if (j < rhs.number.size()) {
new_digit += tmp.number[i]*rhs.number[j];
}
number[i+j] = new_digit % 10;
carry = new_digit/10;
}
}
while(number.back() == 0) {
number.pop_back();
}
return *this;
}
示例14: processLayers
/**
* This method processes all of the layers in the level.
*/
void Level::processLayers(std::string& layer_text)
{
// Remove all white space from the layer data because it may be indented, and spaces aren't needed.
layer_text.erase(std::remove(layer_text.begin(), layer_text.end(), ' '), layer_text.end());
// Remove newlines from the beginning and end of the layer data, as they would mess with splitting by lines.
layer_text.erase(layer_text.begin());
layer_text.pop_back();
// Split the layer data by line.
auto layer_data = Tools::splitString(layer_text, '\n');
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (layer_data[y][x] == '2')
{
// Add walls.
wall_rects.push_back({x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE});
}
}
}
map_data.push_back(layer_data);
}
示例15: pack_key_range
void etcd_packer::pack_key_range(rapidjson::Value &json_val, const std::string &key, std::string range_end, rapidjson::Document &doc) {
if ("+1" == range_end) {
range_end = key;
bool need_plus = true;
while (!range_end.empty() && need_plus) {
char c = range_end[range_end.size() - 1];
if (static_cast<unsigned char>(c) == 0xff) {
range_end.pop_back();
} else {
range_end[range_end.size() - 1] = c + 1;
need_plus = false;
}
}
if (range_end.empty() && need_plus && !key.empty()) {
range_end = "\0";
}
}
if (!key.empty()) {
pack_base64(json_val, "key", key, doc);
}
if (!range_end.empty()) {
pack_base64(json_val, "range_end", range_end, doc);
}
}