std :: string sprintf [英] std::string sprintf
问题描述
嘿
Iam偶尔会使用像
char buffer [1024];
sprinf(buffer," Hello test%d%) s",someint,somestring);
是否有任何_convenient_和buffer overflow安全等效于
使用std :: string?
谢谢
Hey
Iam occaisonally using something like
char buffer[1024];
sprinf(buffer,"Hello test %d %s",someint,somestring);
Is there any _convenient_ and buffer overflow secure equivalent for that
using std::string?
Thanks
推荐答案
" Frank Neuhaus" < FN ****** @ uni-koblenz.de>在留言中写道
news:di ********** @ cache.uni-koblenz.de ...
"Frank Neuhaus" <fn******@uni-koblenz.de> wrote in message
news:di**********@cache.uni-koblenz.de...
嘿
Iam occaisonally使用类似
char buffer [1024];
sprinf(缓冲区,Hello test%d%s,someint,somestring);
是否有_convenient_和buffer溢出安全相当于
使用std :: string?
Hey
Iam occaisonally using something like
char buffer[1024];
sprinf(buffer,"Hello test %d %s",someint,somestring);
Is there any _convenient_ and buffer overflow secure equivalent for that
using std::string?
查找''std :: ostringstream''
-Mike
Look up ''std::ostringstream''
-Mike
Frank Neuhaus写道:
Frank Neuhaus wrote:
嘿
嘿你自己
Iam偶尔使用像
char buffer [1024];
sprinf(缓冲区,Hello test%d%s,someint,somestring);
>使用std :: string是否有_convenient_和buffer overflow安全等效?
Hey
Hey yourself
Iam occaisonally using something like
char buffer[1024];
sprinf(buffer,"Hello test %d %s",someint,somestring);
Is there any _convenient_ and buffer overflow secure equivalent for that
using std::string?
有一个snprintf,IIRC ...
一般来说,我所知道的唯一合理的方式是
std :: ostringstream os;
os<< 你好测试 << someint<< ''''<< somestring;
std :: string buffer(os.str());
//这里''缓冲''有字符串
V
There is a snprintf, IIRC...
Generally speaking, the only reasonable way I know is
std::ostringstream os;
os << "Hello test " << someint << '' '' << somestring;
std::string buffer(os.str());
// here ''buffer'' has the string
V
Frank Neuhaus写道:
Frank Neuhaus wrote:
Iam偶尔使用像
char buffer [1024]这样的东西;
sprinf(缓冲区,Hello test%d%s,someint,somestring);
是否有任何_convenient_和buffer overflow安全等效于
使用std: :string?
Iam occaisonally using something like
char buffer[1024];
sprinf(buffer,"Hello test %d %s",someint,somestring);
Is there any _convenient_ and buffer overflow secure equivalent for that
using std::string?
Boost.Format通过重载operator%来实现printf样式的格式化。它虽然
对我来说仍然感觉不是很好。你做什么,基本上,
是创建一个格式化程序对象,它有一个内部流缓冲区,保存格式化序列的
。然后你可以获取它的字符串值并将它分配给std :: string。
示例:
std :: string s;
s = str(格式("%d%d")%11%22);
参见 http://www.boost.org/libs/format/index.html 更多例子。
-
Matthias Kaeppler |电话:+49 631 3405805
Gerhart-Hauptmann-Str。 16a |手机:+49 176 20108693
D-67663凯撒斯劳滕|电子邮件:有限状态点组织的matthias
Boost.Format has printf-style formatting by overloading operator%. It
still doesn''t feel very printf-ish to me though. What you do, basically,
is create a formatter object which has an internal stream buffer holding
the formatted sequence. You can then take its string value and assign it
to a std::string.
Example:
std::string s;
s = str( format(" %d %d ") % 11 % 22 );
See http://www.boost.org/libs/format/index.html for more examples.
--
Matthias Kaeppler | Tel: +49 631 3405805
Gerhart-Hauptmann-Str. 16a | Mob: +49 176 20108693
D-67663 Kaiserslautern | E-Mail: matthias at finitestate dot org
这篇关于std :: string sprintf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!