?
Solved

Roguewave's RWCString vs string

Posted on 2000-04-09
7
Medium Priority
?
2,542 Views
Last Modified: 2008-02-01
I'm thinking about using Roguewave's RWCString
class instead of normal strings. Then I though
"Why?" and I started read the documentation,
but I couldn't find any info that would explain
exactly what are the main differences between
it and normal string?

Of course I can't remember every method normal
string class offers and comparing all of them would
to Roguewave's methods would be a little bit
too much work. Has anyone used this class
and what benefits it offers comparing to
normal string class?
0
Comment
Question by:tonitop
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Expert Comment

by:jasonclarke
ID: 2700161
Presumably you are talking about the std::string class.

I would think that one of the main reasons that there is RWCString and not just std::string is that RWCString has been around for most people for a lot longer.  RWCString was available long before std::string was,  I was using it at least 7 years ago.

For 'normal' string uses, I guess RWCString probably is similar.  I use std::strings now and don't find myself wishing for RWCString features.
0
 
LVL 3

Expert Comment

by:TEFKASG
ID: 2702536
Are you using other RW classes?  If not, I would just use the std string and not bother with the rogue wave libraries.
  I haven't used RW strings in a while, but as jasonclarke said, using std::strings I don't miss the RW version.  Just my 2 cents worth.
0
 
LVL 9

Expert Comment

by:Pacman
ID: 2703378
Can't tell you the diffs because I only use RWCString.
But what I hate using RWCString is the following:

There's no type cast operator to (char*), only to (const char*).
So if you have a function which wants char* as a parameter (even if it doesn't write to this pointer) then you have to write such code:

RWCString myString = "hi folks!";

DoSomething( (char*)(const char*)myString );

This is ugly. Don't know if your other string class is better here ...

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:jasonclarke
ID: 2703405
std::string doesn't cast to char * or const char* at all, you have to use the c_str() method, which returns a const char*.  (Can't remeber why now,  but I think, as with almost everything in STL there is a good reason for it).

You shouldn't complain about this behaviour in RW, it is the right thing to do.  Casting to char* is really quite bad because, as you say it would give the user the opportunity to stomp on RWs string buffer.  

Forcing you to do this kind of cast is a safety measure,  it highlights that what you are doing is dodgy and best avoided.



0
 
LVL 9

Expert Comment

by:Pacman
ID: 2703473
I know it's right but I don't like it. I've never tried to write to a const char ... ;) ...
0
 
LVL 2

Expert Comment

by:abesoft
ID: 2703878
A comment on RWCString casting... (Following Pacman's comments)

I prefer to change:
DoSomething( (char*)(const char*)myString );

to:

DoSomething( const_cast<char *>( myString.Data()));

or:

DoSomething( (char *) myString.Data());

Double casting seems a little too obscure.  The const_cast version nicely documents what you are doing, although it is a little wordy.  I usually use the last form.
0
 
LVL 2

Accepted Solution

by:
abesoft earned 300 total points
ID: 2703960
Two differences that I've noticed are substrings and regular expressions.  (I don't use std::string too often, so I'm not sure if somebody has implemented these as extensions to the library - I'm sure that they have....)

In std::string::substr( start, end) merely returns a copy of the string between those two positions.  In RWCSubString, you get a reference to the actual string that the substring is extracted from, so:
  RWCString s("What I tell you is true.");
  // Create a substring and use it as an lvalue:
  s(19, 0) = "three times ";
  cout << s << endl;
Program output:

What I tell you is three times true.

Which is kind of neat when you want to modify a portion of a string.

Also, regular expressions are great tools, although they do tend to be difficult to read and maintain, and most developers who use them quickly become addicted.  RW includes two subtly different regexp classes, but that's not really a concern right now.  As an example:  

  RWCString aString("Hark! Hark! the lark");
  // A regular expression matching any lowercase word or end of a  
  //word starting with "l":     RWCRExpr re("l[a-z]*");
  cout << aString(re) << endl;  // Prints "lark"

Both of these features are not strictly part of RWCString, but they do act on RWCStrings, so I consider the classes related.

Hope this helps.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question