[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Roguewave's RWCString vs string

Posted on 2000-04-09
7
Medium Priority
?
2,517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

649 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