Starting a class and may need help

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Postby icujc » Sat Sep 27, 2003 12:51 pm

omnius wrote:
icujc wrote:As far as I can remember <string> is used for Null-terminated character arrays often referred to as C strings

No, definitely not. <string> is for std::string, not C-strings. Any reasonably modern beginner's book should cover this.


The <string> header defines the string type, and is a class template. It provides type saftey to null-terminated strings.

The <cstring> supplys funcionality for null-terminated strings similar to what a string object provides.

<cstring> does not define the string object and <string> does. The string object does not require the use of the functions provided by <cstring> like strcmp(), strcat(), and strncat(). With the string object you can use the overloaded Arithmetic operators and logical operators to perform such tasks as comparing, adding to the begining, or adding to the end.
--

"Computers are like air conditioners - They can't do their job
properly if you open windows."
User avatar
icujc
 
Posts: 83
Joined: Mon Sep 22, 2003 3:41 pm
Location: Alabama

Postby omnius » Sat Sep 27, 2003 2:19 pm

icujc wrote:The <string> header defines the string type, and is a class template. It provides type saftey to null-terminated strings.

What is that supposed to mean, 'provides type safety to null-terminated strings'? Is it some kind of attempt at justification for your earlier statement that "<string> is used for Null-terminated character arrays often referred to as C strings"? (Which is blatantly incorrect).

It's not clear to me whether you don't fully understand the difference between std::string and null-terminated character arrays, or whether it's just the way you express yourself, but it reads confusing to me for other people to keep talking about std::string in conjunction with null-terminated 'strings'. The two are quite different.

std::string has no relationship to null-terminated character arrays other than the functionality provided to convert between the two.
omnius
 
Posts: 496
Joined: Wed Sep 24, 2003 12:03 pm

Postby Guest » Sat Sep 27, 2003 3:21 pm

raimo wrote:Indeed, <cstring> should contain the basic functions to manipulate null-terminated character arrays, like strcpy, strcat and so.


Yeah that`s right...the c-string header files contains declarations for only functions to manipulate on c-strings *BUT DOESN`T CONTAIN ANY CLASSES OR OBJECTS DEFINED* so when u define an object from type "string" you surely need to #include<string> not cstring so that`s the reason why ur code didn`t work.
Guest
 

Previous

Return to For Beginners

Who is online

Users browsing this forum: No registered users and 2 guests