Cumbersome string handling...

H

Heraklit

Dear experts,

a long time ago I spent a lot of time writing a useful program on
linux/g++ with the String.h package (maybe somebody remembers this
class String).

Now, I am trying to reactivate this, but cannot compile it anywhere
anymore, since the library is obsolete for a long time and has been
removed from current g++ distributions.

I've started implementing everything with the string class present in
the ansi c++ standard library, but I am getting more and more the
impression that I have to keep reinventing the wheel. There are no
automatic conversions integer->string available (how do I do something
like sprintf here?!?), "split"ting some string into parts has gone
missing, ...

What's your advice, how should I handle this problem? Are there any
(free as GPL or LGPL) equivalent libraries available?

Somebody must have had this difficulty before...

Regards, Andreas
 
A

Aggro

Heraklit said:
I've started implementing everything with the string class present in
the ansi c++ standard library, but I am getting more and more the
impression that I have to keep reinventing the wheel. There are no
automatic conversions integer->string available (how do I do something
like sprintf here?!?), "split"ting some string into parts has gone
missing, ...

[38.1] How do I convert a value (a number, for example) to a std::string?
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.1

[38.2] How do I convert a std::string to a number?
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.2
What's your advice, how should I handle this problem? Are there any
(free as GPL or LGPL) equivalent libraries available?

std::string, comes with the standard C++.

If you have lots of code and you find it easier to write your own string
class, try to do it so that you use as much std::string in it as
possible, to make things easier for you. Implement only functions which
you are using so spare yourself from extra work.
 
M

Mike Wahler

Heraklit said:
Dear experts,

a long time ago I spent a lot of time writing a useful program on
linux/g++ with the String.h package (maybe somebody remembers this
class String).

Now, I am trying to reactivate this, but cannot compile it anywhere
anymore, since the library is obsolete for a long time and has been
removed from current g++ distributions.

I've started implementing everything with the string class present in
the ansi c++ standard library,
Why?

but I am getting more and more the
impression that I have to keep reinventing the wheel.

You are.
There are no
automatic conversions integer->string available

Yes, there are.
(how do I do something
like sprintf here?!?),

int i(123);
std::eek:stringstream oss;
oss << i;
std::string s(oss.str());
"split"ting some string into parts has gone
missing, ...
std::string::find()
std::string::substr()


What's your advice, how should I handle this problem?

Study the documentation for standard types 'std::string'
and the stringstream types.

Are there any
(free as GPL or LGPL) equivalent libraries available?
Somebody must have had this difficulty before...

I don't have difficulty with std::string at all. After
using 'C-style strings' for almost two decades, I find
'std::string' a joy to use.

$.02,
-Mike
 
T

tom_usenet

Dear experts,

a long time ago I spent a lot of time writing a useful program on
linux/g++ with the String.h package (maybe somebody remembers this
class String).

Now, I am trying to reactivate this, but cannot compile it anywhere
anymore, since the library is obsolete for a long time and has been
removed from current g++ distributions.

I've started implementing everything with the string class present in
the ansi c++ standard library, but I am getting more and more the
impression that I have to keep reinventing the wheel. There are no
automatic conversions integer->string available (how do I do something
like sprintf here?!?), "split"ting some string into parts has gone
missing, ...

What's your advice, how should I handle this problem? Are there any
(free as GPL or LGPL) equivalent libraries available?

Somebody must have had this difficulty before...

Yes, std::string has an over-fat interface, doesn't do anything really
well, and yet doesn't offer much functionality; if it were to be
created from scratch right now with the benefit of the experience
gained since the early '90s when it was written, it would look a lot
different.

A commercial alternative is:
http://www.utilitycode.com/str/

Boost are adding a string utility library. 1.32 will be formally
released soon, but in the meantime:
http://boost-consulting.com/boost/index.htm

Boost already has useful stuff for converting between types and to
strings - see lexical_cast and the Format library in 1.31 at
www.boost.org

Tom
 
M

Mark

On Wed, 01 Sep 2004 18:11:43 +0100, tom_usenet

[...]
Yes, std::string has an over-fat interface, doesn't do anything really
well, and yet doesn't offer much functionality; if it were to be
created from scratch right now with the benefit of the experience
gained since the early '90s when it was written, it would look a lot
different.

Couldn't agree more. It's a shame when I look at the perfomance
penalties of std::string for some of our applications where runtime
perfomance is extremely critical.
Never seen this before, nontheless, pretty slick ...
Boost are adding a string utility library. 1.32 will be formally
released soon, but in the meantime:
http://boost-consulting.com/boost/index.htm

Boost already has useful stuff for converting between types and to
strings - see lexical_cast and the Format library in 1.31 at
www.boost.org

Tom
Haven't jumped on the boost bandwagon yet. In any event, ...

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top