By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

how to replace sscanf in C++,using <string>s

P: n/a
I want to replace the following line:

sscanf(mybuf,"%s=%s\n",sz1,sz2);

with something that produces the same effect, only with
dynamic storage i.e string s which is safer.

I might try this:

sscanf(mybuf.c_str(),"%s=%s\n",string1.c_str(),str ing2.c_str());

but unsuprisingly this causes an error at runtime since there is nothing to
stop a memory overrun happening.Additionally there is no compile time check
as sscanf uses varargs.

Can anyone recommend the quickest way of acheiving this, short of writing
my own parser.

Mark
Aug 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mark wrote:
I want to replace the following line:

sscanf(mybuf,"%s=%s\n",sz1,sz2);

with something that produces the same effect, only with
dynamic storage i.e string s which is safer.

I might try this:

sscanf(mybuf.c_str(),"%s=%s\n",string1.c_str(),str ing2.c_str());

but unsuprisingly this causes an error at runtime since there is nothing to
stop a memory overrun happening.Additionally there is no compile time check
as sscanf uses varargs.

Can anyone recommend the quickest way of acheiving this, short of writing
my own parser.


Something similar to

string::size_type eq = mybuf.find('=');
string string1 = mybuf.substr(0, eq), string2 = mybuf.substr(eq+1);

V
Aug 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.