By far the most common mistake is to not use the full power of the module. If you find yourself writing a little "helper" class, consider why you are doing it. Or, if what you are writing seems a little clumsy, then maybe there's a more elegant approach. A bit of searching through the Essential Tools Module manuals may uncover just the thing you are looking for!
Here is a surprisingly common example:
main(int argc, char* argv[]){ char buf[120]; //uh oh: possible overflow ifstream fstr(argv[1]); RWCString line; while (fstr.readline(buf,sizeof(buf)) { line = buf; //hmm: extra copy cout << line; } } |
This program reads lines from a file specified on the command line and prints them to standard output. By using the full abilities of the RWCString class it could be greatly simplified as follows:
main(int argc, char* argv[]){ ifstream fstr(argv[1]); RWCString line; while (line.readLine(fstr)) { cout << line; } } |
There are countless other such examples. The point is, if it looks awkward to you, most likely there's a better way!
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.