Author: Odd Gunnar Malin
Date: 13:21:30 01/24/03
Go up one level in this thread
On January 24, 2003 at 05:38:27, Steffen Jakob wrote: >On January 24, 2003 at 04:50:59, Odd Gunnar Malin wrote: > >>On January 24, 2003 at 03:22:37, Steffen Jakob wrote: >> >>>On January 24, 2003 at 03:15:55, Joshua Haglund wrote: >>> >>>>What do I need to #include to use strlen? >>>>I've tried almost everything I can think of! >>>>(C++) >>> >>>Don't use strlen() in C++ but std::string and its member function length(). :-) >>> >>>Greetings, >>>Steffen. >> >>Sometimes you have to use routines from c's string.h, then to not confuse >>yourself to much and also take care of std namespace, <cstring> should be used >>instead of <string.h>. >>The same goes for other (<ctime>, <cstdlib> etc...). >> >>A sample I use a lot is the following in the top of files. >> >>#ifdef _DEBUG >> #define _CRTDBG_MAP_ALLOC >> #include <cstdlib> >> #include <crtdbg.h> >>#endif >> >>Another could be if you want a case insensitive compare, then it's easier to use >>cstring's stricmp instead of writing your own in c++. > >... only if you are lucky and have "stricmp()" available on your system because >it isn't part of the Ansi C standard. ;-) > If you know you are working on Windows platform there is a very easy way to compare c-strings with lstrcmpi(). This routine take care of the user defined local settings before it compare. stricmp() have to be preset with setlocale first I think. But you are right stricmp isn't Ansi C. >In Scott Meyers "Effective STL" you can read that to compare case-insensitive >strings isn't sometimes as easy as one might think (e.g. if you compare >non-english strings; in french 'é' might be treated equivalent to 'E'). He >offers solutions for the trivial case as well for the advanced cases in his book >(I strongly recommend to C++ programmers to read everything from Meyers). > Hmm.. I have two books I use, Stroustrup's for C++ and Knuth's TAOCP for general discussion. When I converted from fortran, Stroutstrup's book was following dec's C++ for VMS and I realy liked it so I have upgraded it to third edition to get some of the stl stuff. Most often when you create small utilities it isn't the code that have to be effective but the job itself. Very often you have a man waiting for a little converter etc. to be finish before lunchtime. I'm sure I could have profited bye reading some newer book's to get rid of some of my habits, There is many 'if (size<0) return;' etc. in my code, mainly because I reuse so much. Odd Gunnar
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.