I have a question concerning using strings in classes. First, what's the difference between #include <string> and #include <cstring> . Second, when using string in a class, is it necessary to have a pointer for whatever reason? (I'm not entirely, if not at all, sure why they are being used)
In the textbook I have, they have something like this:
<cstring> contains functions related to c strings. std::strcpy, std::strlen, std::strcat etc.
<string> contains the class std::string and some other functions related to std::string.
when using string in a class, is it necessary to have a pointer for whatever reason?
This depends on what kind of string you are using. A c string is a null terminated array of characters. Often a pointer is used to point to the first character in the c array. You could use a fixed length array instead of a pointer but that could waste space and be problematic if the array is too short to store a string.
When using std::string there is often no need to use a pointer. Using std::string is generally easier to use than c strings.
Oh ok, I have this program called Microsoft Visual C++ and I was using the std::string in a class I was writing, but I have been getting an error as I typed the class out.
Apologies for the double post, program too long to have in one whole reply box. But yeah, I don't know what's wrong with the program, the compiler is saying somethign about the 'string' in the class or something