本文整理汇总了C++中std::string::at方法的典型用法代码示例。如果您正苦于以下问题:C++ string::at方法的具体用法?C++ string::at怎么用?C++ string::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::string CEqParserV2::_getFcnSubstr(std::string &equation, int &it)
{
//-//-//-//-//-//-//-//-//-//-//-//
// Example: 2+func((2+1),3)+42
// ^ ^
//-//-//-//-//-//-//-//-//-//-//-//
bool doExit = false;
bool initOk = false;
int parCount = 0;
std::string rVal = "";
while ((unsigned)it < equation.length() && !doExit)
{
char chr = equation.at(it);
it++;
int parCountDelta = cc::parseParanthesis(chr);
parCount += parCountDelta;
if (parCountDelta==1)
{
parCount++;
initOk = true;
}
rVal.push_back(chr);
if (initOk && parCount == 0)
{
return rVal;
}
}
return "";
}
示例2: LoadSecurity
void WorldSession::LoadSecurity(std::string securitystring)
{
std::list<char> tmp;
bool hasa = false;
for(uint32 i = 0; i < securitystring.length(); ++i)
{
char c = securitystring.at(i);
c = tolower(c);
if(c == '4' || c == '3')
c = 'a'; // for the lazy people
if(c == 'a')
{
// all permissions
tmp.push_back('a');
hasa = true;
}
else if(!hasa && (c == '0') && i == 0)
break;
else if(!hasa || (hasa && (c == 'z')))
{
tmp.push_back(c);
}
}
permissions = new char[tmp.size()+1];
memset(permissions, 0, tmp.size()+1);
permissioncount = (uint32)tmp.size();
int k = 0;
for(std::list<char>::iterator itr = tmp.begin(); itr != tmp.end(); ++itr)
permissions[k++] = (*itr);
if(permissions[tmp.size()] != 0)
permissions[tmp.size()] = 0;
sLog.outDebug("Loaded permissions for %u. (%u) : [%s]", this->GetAccountId(), permissioncount, securitystring.c_str());
}
示例3: split
/*!
* @if jp
* @brief 文字列の分割
* @else
* @brief Split of string
* @endif
*/
unsigned int CorbaNaming::split(const std::string& input,
const std::string& delimiter,
std::vector<std::string>& results)
{
typedef std::string::size_type size;
size delim_size = delimiter.size();
size found_pos(0), begin_pos(0), pre_pos(0), substr_size(0);
if (input.substr(0, delim_size) == delimiter)
begin_pos = pre_pos = delim_size;
while (1)
{
REFIND:
found_pos = input.find(delimiter, begin_pos);
if (found_pos == std::string::npos)
{
results.push_back(input.substr(pre_pos));
break;
}
if ('\\' == input.at(found_pos - 1))
{
begin_pos = found_pos + delim_size;
goto REFIND;
}
substr_size = found_pos - pre_pos;
if (substr_size > 0)
{
results.push_back(input.substr(pre_pos, substr_size));
}
begin_pos = found_pos + delim_size;
pre_pos = found_pos + delim_size;
}
return results.size();
}
示例4:
void c_rpc_server::c_session::send_response(nlohmann::json json_response)
{
try {
const std::string response = json_response.dump();
assert(response.size() <= std::numeric_limits<uint16_t>::max());
uint16_t size = static_cast<uint16_t>(response.size());
m_write_data.resize(size + 2); ///< 2 first bytes for size
m_write_data.at(0) = static_cast<char>(size >> 8);
m_write_data.at(1) = static_cast<char>(size & 0xFF);
for (size_t i = 0; i < response.size(); ++i)
m_write_data.at(i + 2) = response.at(i);
// send response
dbg("send packet");
dbg(m_write_data);
std::array<unsigned char, crypto_auth_hmacsha512_BYTES> hash;
int ret = crypto_auth_hmacsha512(hash.data(), reinterpret_cast<unsigned char *>(&m_write_data.at(2)), size, m_rpc_server_ptr->m_hmac_key.data());
if (ret != 0) _throw_error(std::runtime_error("crypto_auth_hmacsha512 error"));
dbg("hmac");
//for (const auto & byte : hash) std::cout << std::hex << "0x" << static_cast<int>(byte) << " ";
//std::cout << std::dec << std::endl;
std::array<boost::asio::const_buffer, 2> buffers = {
{boost::asio::buffer(m_write_data.data(), m_write_data.size()),
boost::asio::buffer(hash.data(), hash.size())}
};
m_socket.async_write_some(buffers,
[this](const boost::system::error_code& error, std::size_t bytes_transferred) {
write_handler(error, bytes_transferred);
});
}
catch (const std::exception &e) {
_erro( "exception in execute_rpc_command " << e.what() );
_erro( "close connection\n" );
delete_me();
return;
}
}
示例5: nameToDescription
std::string Util::nameToDescription(const std::string& name)
{
std::stringstream ss;
bool prevWasUpper = false;
bool nextToUpper = false;
for (int i = 0; i < name.length(); i++)
{
char c = name.at(i);
if (isupper(c))
{
if (!prevWasUpper && i != 0)
{
ss <<" ";
}
prevWasUpper = true;
}else {
prevWasUpper = false;
}
if (i == 0 || nextToUpper) {
c = toupper(c);
nextToUpper = false;
}
if (c == '_') {
ss <<" ";
nextToUpper = true;
}else{
ss <<c;
}
}
return ss.str();
}
示例6: RemoveComments
std::string RemoveComments(const std::string Str)
{
std::string Result;
int k = 0;
int AwatingEOL = 0;
ptrdiff_t len = Str.length() - 1;
for (ptrdiff_t i = 0; i < len; i++)
{
if (AwatingEOL)
{
if (Str[i] != '\n')
continue;
else
{
AwatingEOL = 0;
continue;
}
}
else
{
if (Str[i] == '/' && Str[i + 1] == '/')
{
AwatingEOL = true;
continue;
}
else
{
Result.push_back(Str.at(i));
k++;
}
}
}
Utility::ReplaceAll(Result, "[\\n\\r ]", "");
return Result;
}
示例7: set_dir
bool stage_t::set_dir( std::string const & dir)
{
if ( dir_exists(dir)){
if ( (m_temp_dir_name != "") && (m_remove_dir_on_exit == true) && (m_temp_dir_name != dir)){
std::string cmd = "rmdir " + m_temp_dir_name;
// std::cout <<" cmd is " << cmd << '\n';
int result = system (cmd.c_str());
if (result == -1){
std::cout << "warning couldnt remove old temp dir\n";
}
}
m_remove_dir_on_exit = false;
if ( dir.at(dir.length() -1) != get_platform()->get_dir_sep().at(0)){
m_temp_dir_name = dir + get_platform()->get_dir_sep();
}else{
m_temp_dir_name = dir;
}
return true;
}else{
std::cout << "dir not found\n";
return false;
}
}
示例8: filterIsValid
bool Database::filterIsValid(std::string filter) {
/* Clean the filter term of any caps*/
std::string cleaned = "";
for (unsigned int i = 0; i < filter.length(); ++i) {
cleaned.push_back(tolower(filter.at(i)));
}
if (cleaned.compare("age") == 0) return true;
else if (cleaned.compare("ssn") == 0) return true;
else if (cleaned.compare("email") == 0) return true;
else if (cleaned.compare("phone") == 0) return true;
else if (cleaned.compare("job") == 0) return true;
if (filter.compare("age") == 0) return true;
else if (filter.compare("ssn") == 0) return true;
else if (filter.compare("email") == 0) return true;
else if (filter.compare("phone") == 0) return true;
else if (filter.compare("job") == 0) return true;
std::cout << "Error: Invalid filter" << std::endl;
return false;
}
示例9: dump
void dump()
{
const std::string grayscale = " .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%[email protected]$";
std::cerr << "\n";
double max = 0.0;
for(double f: frequencies) {
max = std::max(f, max);
}
const double scale = (grayscale.size() - 1) / max;
static bool printed = false;
if(printed) {
std::cerr << "\033[19A";
}
std::cerr << "+--------------------------------------------------+\n";
for(uint h = 0 ; h < 256; h += 16) {
std::cerr << "|";
for(uint l = 0 ; l < 16; l += 1) {
std::cerr << " " << grayscale.at(scale * frequencies[h + l]);
}
std::cerr << " |\n";
}
std::cerr << "+--------------------------------------------------+\n";
printed = true;
}
示例10: while
std::vector< std::string > list_devices( std::string p, unsigned char t, bool rec )
{
std::vector< std::string > v_dev;
DIR *dir;
struct dirent *dir_ent;
// optionally correction of path param
if( p.at( p.length()-1 ) != '/' ) { p += '/'; }
if( (dir = opendir( p.c_str() )) )
{
while( (dir_ent = readdir( dir )) )
{
if( (strcmp( dir_ent->d_name, "." ) == 0) ||
(strcmp( dir_ent->d_name, ".." ) == 0)
) { continue; /* ignore + jump to next */ }
else
{
std::string tmp_str = p;
tmp_str += dir_ent->d_name;
if( dir_ent->d_type == t )
{ v_dev.push_back( std::string( tmp_str ) ); }
if( (dir_ent->d_type == DT_DIR) && rec )
{
std::vector< std::string > tmp_v;
v_dev.push_back( std::string( tmp_str ) );
tmp_v = list_devices( tmp_str, t, rec );
v_dev.insert( v_dev.end(), tmp_v.begin(), tmp_v.end() );
} else { continue; /* ignore + jump to next */ }
} // end pathcheck if
} // end while loop
closedir( dir );
} else { /* nothing to do */ }
return v_dev;
}
示例11: isIndex
vector<size_t> MicroCompiler::_ParseArgumentIndices(const std::string &action)
{
vector<size_t> indices;
bool isIndex(false);
for(size_t i = 0; i < action.size(); i++)
{
if (action.at(i) == '$')
{
if (isIndex)
{
indices.push_back(_LeftIndex);
isIndex = false;
}
else
isIndex = true;
continue;
}
else if(isIndex)
{
const size_t comma = action.find_first_of(',', i);
const size_t rParen = action.find_first_of(')', i);
const size_t numBytes = (comma < rParen ? comma : rParen) - i;
const string num(action.substr(i, numBytes));
indices.push_back(_RightIndex + boost::lexical_cast<size_t>(num) -1);
isIndex = false;
}
}
if (Debug)
{
cout << "Indices for : " << action << " is ";
std::copy(indices.begin(), indices.end(), std::ostream_iterator<size_t>(std::cout, ","));
cout << endl;
}
return indices;
}
示例12:
protein::protein(std::string p, double temp)
{
seq = p;
pH = temp;
std::cout << "Calculating net charge for " << p.length() << " membered protein\n\n";
//Allocate memory to chop string
residue = new char[p.length()];
size = p.length();
for (unsigned count = 0; count < p.length(); count++)
{
//Chop string into char
residue[count] = p.at(count);
}
protein::storeCharge(pH);
//Find total charge using net charge at R group.
for (unsigned count = 0; count < size; count++)
{
totalCharge += ratio[protein::getNumber(residue[count])][2];
}
//Add to the total charge the net charge at COOH and NH3.
totalCharge += ratio[protein::getNumber(residue[0])][1];
totalCharge += ratio[protein::getNumber(residue[size - 1])][0];
std::cout << "\nNet Charge of Peptide : " << totalCharge << std::endl;
}
示例13: generateAllCombinations
std::vector<std::string> generateAllCombinations(std::string s)
{
std::vector<std::string> v;
std::vector<std::string> combinations;
if (s.size() == 0)
{
return v;
}
if (s.size() == 1)
{
v.push_back(s);
return v;
}
char characterToMix = s.at(0);
s = s.substr(1, s.size() - 1);
combinations = generateAllCombinations(s);
for (size_t i = 0; i < combinations.size(); ++i)
{
std::string combination = combinations[i];
for (size_t j = 0; j <= combination.size(); ++j)
{
std::string left = combination.substr(0, j);
std::string right = combination.substr(j, combination.size() - j);
v.push_back(left + characterToMix + right);
}
}
return v;
}
示例14: setText
void Dialog::setText(std::string str)
{
unsigned int maxSize(40);
unsigned int maxLine(3);
if(str.length() >= maxSize)
{
for(unsigned int j = 1 ; j <= (unsigned int)(str.length()/maxSize); j++)
{
str.insert(j * maxSize , "\n");
}
}
unsigned int nb = 0;
for(unsigned int j = 0 ; j < str.length(); j++)
{
if(str.at(j) == '\n')
{
nb++;
if(nb == maxLine)
{
texts.push_back(str.substr(0, j + 1));
str.erase(0, j + 1);
nb = 0;
j = 0;
}
}
}
if(str.length() > 0 )
{
texts.push_back(str);
}
}
示例15: token_word
std::string token_word(const std::string& in) {
int pos = -1;
int digits_prefixed = 0;
int nalpha = 0;
int len = in.size();
std::vector<char> cv;
int last_quirk = -1;
while (++pos < len) {
char ch = in.at(pos);
if (std::isdigit(ch)) {
if (digits_prefixed > 0) {
last_quirk = pos;
break;
}
digits_prefixed--;
cv.push_back(std::tolower(ch));
} else if (std::isalpha(ch)) {
if (digits_prefixed < 0)
digits_prefixed = -digits_prefixed;
cv.push_back(std::tolower(ch));
nalpha++;
} else {
if (digits_prefixed < 0)
digits_prefixed = -digits_prefixed;
last_quirk = pos;
if ((ch == '-' || ch == '\'') && pos != 0) {
cv.push_back(ch);
} else {
break;
}
}
}
if (last_quirk == pos || (digits_prefixed > 0 && nalpha == 0))
cv.clear(); // invalid word
return std::string(cv.begin(),cv.end());
}