#include string.h and #include "string6.h" , item20.cc, More C++

greenspun.com : LUSENET : Steve Heller's books : One Thread

Doubtless you have covered it someplace and I have forgotten already . . . but why do you #include both and "string6.h" in code\item20.cc (Figure 2.3, page 12, MORE C++)? Doesn't string6.h encompass everything that is in string.h?

Cliff Wirt

-- Cliff Wirt (DementedMagpie@hotmail.com), April 11, 1999


Actually, string6.h is the declarations for my C++ string class, whereas string.h is the header that declares the old C-style "string" (actually char*) operations, some of which are used in the implementation of my string class. That's why both of them are necessary.

-- Steve Heller (stheller@koyote.com), April 11, 1999.

I'm still confused. If both string.h and string6.h are necessary, why aren't you forced to #include string.h every time you #include string6.h?

I guess my question is: in a number of programs, string6.h is #included unaccompanied by string.h. So why does string.h show up suddenly in this one program, but not in the others where string6.h shows up?

-- Cliff Wirt (DementedMagpie@hotmail.com), April 12, 1999.

As it happens, you don't need to include string.h in item20.cc; it must have been left there from an earlier incarnation of the program that needed that header file. However, to answer your question more generally: string.h and string6.h are different header files that define different structures and functions. Therefore, if you write a program that needs the structures and functions in string.h, you have to include that header, and the same is true for string6.h. Does that answer your question?

-- Steve Heller (stheller@koyote.com), April 12, 1999.

Where is string6.h?

I installed the compiler from the CD in the back of "Learning to Program in C++" onto my Windows 98 2d edition machine but cannot locate string6.h. Accordingly, I get an error message whenever I include string6.h in my code (or try to run the sample programs that use it).

Where can I locate it so that I may continue progressing to more challenging topics?


-- Tristan Cuba (troublemaker71@earthlink.net), July 20, 2002.

Yep. That answers the question. Thanks.

-- Cliff Wirt (DementedMagpie@hotmail.com), April 12, 1999.

Moderation questions? read the FAQ