本文整理汇总了C++中acl::string::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ string::c_str方法的具体用法?C++ string::c_str怎么用?C++ string::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类acl::string
的用法示例。
在下文中一共展示了string::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect_server
bool https_client::connect_server(const acl::string& server_addr,
acl::http_client& client)
{
// 先查本地映射表中有没有映射项
master_service& ms = acl::singleton2<master_service>::get_instance();
const char* addr = ms.get_addr(server_addr.c_str());
if (addr == NULL)
addr = server_addr.c_str();
if (client.open(addr, 60, 60, true) == false)
{
out_.format("connect server %s error", addr);
return false;
}
else
logger_debug(DEBUG, 1, "connect server ok");
if (ssl_conf_)
{
logger_debug(DEBUG, 1, "begin open ssl");
acl::polarssl_io* ssl = new acl::polarssl_io(*ssl_conf_, false);
if (client.get_stream().setup_hook(ssl) == ssl)
{
out_.puts("open ssl client error");
ssl->destroy();
return false;
}
else
logger_debug(DEBUG, 1, "open ssl ok");
}
return true;
}
示例2: test_bitop_xor
static bool test_bitop_xor(acl::redis_string& option, int n)
{
const char* keys[3];
acl::string key, key1, key2, key3;
int ret;
for (int i = 0; i < n; i++)
{
key.format("bit_%s_%d", __keypre.c_str(), i);
key1.format("bit_%s_%d", __keypre.c_str(), i % 1);
key2.format("bit_%s_%d", __keypre.c_str(), i % 2);
key3.format("bit_%s_%d", __keypre.c_str(), i % 3);
keys[0] = key1.c_str();
keys[1] = key2.c_str();
keys[2] = key3.c_str();
option.reset();
ret = option.bitop_xor(key.c_str(), keys, 3);
if (ret < 0)
{
printf("bitop_xor error, key: %s\r\n", key.c_str());
return false;
}
else if (i < 10)
printf("bitop_xor ok, key: %s, bits: %u\n",
key.c_str(), ret);
}
return true;
}
示例3: test_smove
static bool test_smove(acl::redis_set& redis, int n)
{
acl::string src_key, dst_key;
acl::string member;
int ret;
for (int i = 0; i < n; i++)
{
src_key.format("%s_%d", __keypre.c_str(), i);
dst_key.format("dest_%s_%d", __keypre.c_str(), i);
for (int j = 0; j < 1000; j++)
{
member.format("member_%d", j);
redis.clear();
ret = redis.smove(src_key.c_str(), dst_key.c_str(),
member.c_str());
if (ret < 0)
{
printf("smove error, src: %s, des: %s\r\n",
src_key.c_str(), dst_key.c_str());
return false;
}
else if (j * i >= 100)
continue;
printf("smove ok, src: %s, dst: %s, member:%s, ret: %d\r\n",
src_key.c_str(), dst_key.c_str(),
member.c_str(), ret);
}
}
return true;
}
示例4: test_qpeek
static bool test_qpeek(acl::disque& cmd, int i)
{
int count = 1;
cmd.clear();
const std::vector<acl::disque_job*>* jobs =
cmd.qpeek(__queue.c_str(), count);
if (jobs == NULL)
{
printf("qpeek queue: %s error: %s\r\n",
__queue.c_str(), cmd.result_error());
return false;
}
else if (i >= 10)
return true;
printf("qpeek queue: %s ok\r\n", __queue.c_str());
std::vector<acl::disque_job*>::const_iterator cit;
for (cit = jobs->begin(); cit != jobs->end(); ++cit)
{
printf("\tid: %s\r\n", (*cit)->get_id());
printf("\tqueue: %s\r\n", (*cit)->get_queue());
printf("\tjob: %s\r\n", (*cit)->get_body().c_str());
}
return true;
}
示例5: time
qitem(const acl::string& addr, const acl::string& msg)
{
time_t now = time(NULL);
char buf[128];
acl::rfc822 rfc;
rfc.mkdate_cst(now, buf, sizeof(buf));
msg_.format("%s: %s--%s\r\n", buf, addr.c_str(), msg.c_str());
}
示例6: set
bool mem_cache::set(const acl::string& key, const void* dat, size_t dlen,
time_t timeout, unsigned short flags)
{
bool has_tried = false;
struct iovec v[4];
m_line.format("set %s %u %d %d\r\n", key.c_str(),
flags, (int) timeout, (int) dlen);
AGAIN:
if (open() == false)
return (false);
v[0].iov_base = (void*) m_line.c_str();
v[0].iov_len = m_line.length();
v[1].iov_base = (void*) dat;
v[1].iov_len = dlen;
v[2].iov_base = (void*) "\r\n";
v[2].iov_len = 2;
if (m_conn->writev(v, 3) < 0)
{
close();
if (m_retry && !has_tried)
{
has_tried = true;
goto AGAIN;
}
m_ebuf.format("write set(%s) error", key.c_str());
return (false);
}
if (m_conn->gets(m_line) == false)
{
close();
if (m_retry && !has_tried)
{
has_tried = true;
goto AGAIN;
}
m_ebuf.format("reply for set(%s) error", key.c_str());
return (false);
}
if (m_line != "STORED")
{
close();
if (m_retry && !has_tried)
{
has_tried = true;
goto AGAIN;
}
m_ebuf.format("reply(%s) for set(%s) error",
m_line.c_str(), key.c_str());
return (false);
}
return (true);
}
示例7: test_qlen
static bool test_qlen(acl::disque& cmd, int i)
{
cmd.clear();
int ret = cmd.qlen(__queue.c_str());
if (ret < 0)
{
printf("qlen queue: %s error: %s\r\n",
__queue.c_str(), cmd.result_error());
return false;
}
else if (i < 10)
printf("qlen: %d, queue: %s\r\n", ret, __queue.c_str());
return true;
}
示例8: add_cmdline
void redis_commands::add_cmdline(acl::string& line, size_t i)
{
std::vector<acl::string>& tokens = line.split2(" \t|:,;");
if (tokens.size() < 3)
{
logger_warn("skip line(%d): %s", (int) i, line.c_str());
return;
}
acl::string cmd(tokens[0]);
cmd.upper();
if (cmd == "ALL")
{
all_cmds_perm_ = tokens[2];
all_cmds_perm_.lower();
if (all_cmds_perm_ == "warn" || all_cmds_perm_ == "no")
return;
return;
}
REDIS_CMD redis_cmd;
redis_cmd.cmd = cmd;
redis_cmd.broadcast = tokens[1].equal("yes", false) ? true : false;
redis_cmd.perm = tokens[2];
redis_cmd.perm.lower();
if (redis_cmd.perm != "yes" && redis_cmd.perm != "warn")
redis_cmd.perm = "no";
redis_cmds_[cmd] = redis_cmd;
}
示例9: test_hkeys
static bool test_hkeys(acl::redis_hash& redis, int n)
{
acl::string key;
std::vector<acl::string> attrs;
for (int i = 0; i < n; i++)
{
key.format("%s_%d", __keypre.c_str(), i);
attrs.clear();
redis.clear();
if (redis.hkeys(key.c_str(), attrs) == false)
{
printf("hkeys error, key: %s\r\n", key.c_str());
return false;
}
else if (i >= 10)
continue;
printf("hkeys ok, key: %s\r\n", key.c_str());
std::vector<acl::string>::const_iterator cit;
for (cit = attrs.begin(); cit != attrs.end(); ++cit)
{
if (cit != attrs.begin())
printf(", ");
printf("%s", (*cit).c_str());
}
printf("\r\n");
}
return true;
}
示例10: test_hincrbyfloat
static bool test_hincrbyfloat(acl::redis_hash& redis, int n)
{
acl::string key, attr;
double result;
for (int i = 0; i < n; i++)
{
key.format("hincrbyfloat_%s_%d", __keypre.c_str(), i);
attr.format("attr1");
redis.clear();
if (redis.hincrbyfloat(key.c_str(), attr.c_str(),
8.8, &result) == false)
{
printf("hincrbyfloat error, key: %s\r\n", key.c_str());
return false;
}
else if (i >= 10)
continue;
printf("hincrbyfloat ok, key: %s, attr: %s, result: %.2f\r\n",
key.c_str(), attr.c_str(), result);
}
return true;
}
示例11: test_sdiffstore
static bool test_sdiffstore(acl::redis_set& redis, int n)
{
acl::string key, dest_key("set_dest_key");
std::vector<acl::string> keys;
for (int i = 0; i < 10; i++)
{
key.format("%s_%d", __keypre.c_str(), i);
keys.push_back(key);
}
for (int i = 0; i < n; i++)
{
redis.clear();
int ret = redis.sdiffstore(dest_key.c_str(), keys);
if (ret < 0)
{
printf("sdiffstore error, dest: %s\r\n",
dest_key.c_str());
return false;
}
else if (i >= 10)
continue;
printf("sdiffstore ok, dest: %s, count: %d\r\n",
dest_key.c_str(), ret);
}
return true;
}
示例12: test_sadd
static bool test_sadd(acl::redis_set& redis, int n)
{
acl::string key;
std::vector<acl::string> members;
acl::string member;
members.reserve(1000);
for (int j = 0; j < 1000; j++)
{
member.format("member_%d", j);
members.push_back(member);
}
for (int i = 0; i < n; i++)
{
key.format("%s_%d", __keypre.c_str(), i);
redis.clear();
int ret = redis.sadd(key, members);
if (ret < 0)
{
printf("sadd key: %s error\r\n", key.c_str());
return false;
}
else if (i >= 10)
continue;
printf("sadd ok, key: %s, ret: %d\r\n", key.c_str(), ret);
}
return true;
}
示例13: test_zscore
static bool test_zscore(acl::redis_zset& redis, int n)
{
acl::string key;
acl::string member;
bool ret;
double result;
for (int i = 0; i < n; i++)
{
key.format("%s_%d", __keypre.c_str(), i);
for (int j = 0; j < 1000; j++)
{
member.format("member_%d", j);
redis.clear();
ret = redis.zscore(key.c_str(), member.c_str(),
result);
if (ret == false)
{
printf("zscore error, key: %s\r\n",
key.c_str());
return false;
}
else if (j > 0 && j * i < 100)
printf("zscore ok, key: %s, member:%s, "
"score: %.2f\r\n", key.c_str(),
member.c_str(), result);
}
}
return true;
}
示例14: test_get
static bool test_get(acl::redis_string& option, int n)
{
acl::string key;
acl::string value;
for (int i = 0; i < n; i++)
{
key.format("%s_%d", __keypre.c_str(), i);
//key.format("key1_%s_%d", __keypre.c_str(), i);
value.clear();
option.reset();
if (option.get(key.c_str(), value) == false)
{
printf("get key: %s\r\n", key.c_str());
return false;
}
else if (i < 10)
printf("key: %s, value: %s, len: %d\r\n",
key.c_str(), value.c_str(),
(int) value.length());
}
return true;
}
示例15: test_zrangebylex
static bool test_zrangebylex(acl::redis_zset& redis, int n)
{
acl::string key;
const char* min = "[aaa", *max = "(g";
std::vector<acl::string> result;
for (int i = 0; i < n; i++)
{
key.format("%s_%d", __keypre.c_str(), i);
redis.clear();
int ret = redis.zrangebylex(key.c_str(), min, max, &result);
if (ret < 0)
{
printf("zrangebylex error(%s), key: %s\r\n",
redis.result_error(), key.c_str());
return false;
}
if (i >= 10)
{
result.clear();
continue;
}
std::vector<acl::string>::const_iterator cit;
for (cit = result.begin(); cit != result.end(); ++cit)
{
if (cit != result.begin())
printf(", ");
printf("%s", (*cit).c_str());
}
printf("\r\n");
}
return true;
}