473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

string class not standard


In the stroustrup C++ programming language (third edition) i can
find example like this:

string s1= "Hello";

So I imagine string is a standard class.

Furthermore the class in the example is initialized with a
constructor like this

string::string();

The strange thing is this:

Under unixWare i've string class declared only with this
constructor:

string::string(const char* c);

This doesn't seem standard solution! How is it possible?

Why under unixware the string file contain a similar class with
invalid constructors?

Thanks in advance

Jul 23 '05 #1
27 2382
d...@excite.it wrote:
In the stroustrup C++ programming language (third edition) i can
find example like this:

string s1= "Hello";

So I imagine string is a standard class.
Actually, it's std::string: "class string in namespace std"
Furthermore the class in the example is initialized with a
constructor like this

string::string();
The strange thing is this:

Under unixWare i've string class declared only with this
constructor:

string::string(const char* c);

This doesn't seem standard solution! How is it possible?


Because it's not the standard std::string, but a string in another
namespace? Because it's declared earlier as
string::string(const char* c = 0); and the implementation has a
special case for c==0? Because you missed the other declarations
(e.g, the copy ctor seems to be missing as well)

Regards,
Michiel Salters

Jul 23 '05 #2
msalters wrote:
d...@excite.it wrote:
In the stroustrup C++ programming language (third edition) i can
find example like this:

string s1= "Hello";

So I imagine string is a standard class.


Actually, it's std::string: "class string in namespace std"


Standard C++ has no string class.

Jul 23 '05 #3
dj***@excite.it wrote:

In the stroustrup C++ programming language (third edition) i can
find example like this:

string s1= "Hello";

So I imagine string is a standard class.
Yes, it is. Defined in the <string> header in namespace std.
Furthermore the class in the example is initialized with a
constructor like this

string::string();
No, it isn't. First, a temporary string is created using a conversion
constructor from const char*, then s1 is copy-constructed from that. The
compiler can omit the temporary and use the conversion constructor to
construct s1 directly.
The strange thing is this:

Under unixWare i've string class declared only with this
constructor:

string::string(const char* c);

This doesn't seem standard solution! How is it possible?
Either you are using another than the standard string class or your standard
library implementation is broken.
Why under unixware the string file contain a similar class with
invalid constructors?


Show a minimal compilable program that fails on that compiler, together with
the error message generated by it. This way, we can make sure whether the
error is the compiler's or yours.

Jul 23 '05 #4

<ab*********@spambob.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
msalters wrote:
d...@excite.it wrote:
> In the stroustrup C++ programming language (third edition) i can
> find example like this:
>
> string s1= "Hello";
>
> So I imagine string is a standard class.


Actually, it's std::string: "class string in namespace std"


Standard C++ has no string class.


Certainly it does (its standard library does). It's declared
(in namespace 'std') by standard header <string>.

/* completely standard code: */
#include <string>

int main()
{
std::string s("Hello");
return 0;
}

-Mike
Jul 23 '05 #5
Hi

ab*********@spambob.com wrote:
Standard C++ has no string class.


Not sure what you mean.

Markus

Jul 23 '05 #6
Mike Wahler wrote:
<ab*********@spambob.com> wrote in message
Standard C++ has no string class.


Certainly it does (its standard library does). It's declared
(in namespace 'std') by standard header <string>.


Look into the header <string>. I bet you don't find a string class
there.

Jul 23 '05 #7

<ab*********@spambob.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Mike Wahler wrote:
<ab*********@spambob.com> wrote in message
> Standard C++ has no string class.


Certainly it does (its standard library does). It's declared
(in namespace 'std') by standard header <string>.


Look into the header <string>. I bet you don't find a string class
there.


The class std::string is most certainly part of the standard C++ language.
It's a template class. It's defined as:

typedef basic_string<char, char_traits<char>, allocator<char> > string;

Just because it's a template class, doesn't mean it's not a class!

Check the standard if you don't believe it's part of the language.

-Howard

Jul 23 '05 #8
ab*********@spambob.com wrote:
Mike Wahler wrote:
<ab*********@spambob.com> wrote in message
> Standard C++ has no string class.


Certainly it does (its standard library does). It's declared
(in namespace 'std') by standard header <string>.


Look into the header <string>. I bet you don't find a string class
there.


I looked, and I found one. Well, ok, it isn't in <string> itself in the
standard library implementation I use, but in one that is #included by
<string>, but that doesn't really make a difference.
So what now?

Jul 23 '05 #9
Howard wrote:
<ab*********@spambob.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Mike Wahler wrote:
<ab*********@spambob.com> wrote in message
> Standard C++ has no string class.

Certainly it does (its standard library does). It's declared
(in namespace 'std') by standard header <string>.
Look into the header <string>. I bet you don't find a string class
there.


The class std::string is most certainly part of the standard C++

language. It's a template class. It's defined as:

typedef basic_string<char, char_traits<char>, allocator<char> > string;

BTW, this is a class template.
Just because it's a template class, doesn't mean it's not a class!
It's not a class, it's a template with 3 template parameters. If it
were a class usability would be much better. Just look at the compiler
error messages you get using the so called "string class".
Check the standard if you don't believe it's part of the language.


But you just confirmed that there is no string class just a clumsy
basic_string<char, char_traits<char>, allocator<char> > class template.

Don't shoot the messenger ... ;-)

Jul 23 '05 #10

"Abecedarian" <ab*********@spambob.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Howard wrote:
<ab*********@spambob.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
> Mike Wahler wrote:
>> <ab*********@spambob.com> wrote in message
>> > Standard C++ has no string class.
>>
>> Certainly it does (its standard library does). It's declared
>> (in namespace 'std') by standard header <string>.
>
> Look into the header <string>. I bet you don't find a string class
> there.
The class std::string is most certainly part of the standard C++

language.
It's a template class. It's defined as:

typedef basic_string<char, char_traits<char>, allocator<char> >

string;

BTW, this is a class template.


Well, if you want to get technical, the above is just a typedef... an alias
to a template, in this case.
Just because it's a template class, doesn't mean it's not a class!
It's not a class, it's a template with 3 template parameters. If it
were a class usability would be much better. Just look at the compiler
error messages you get using the so called "string class".
Check the standard if you don't believe it's part of the language.


But you just confirmed that there is no string class just a clumsy
basic_string<char, char_traits<char>, allocator<char> > class template.


What's clumsy about it? Perhaps you're just not comfortable with templates?
Don't shoot the messenger ... ;-)


I always shoot the messenger. Even for good news. I just like doing things
like that. :-O

But, I fail to see your point. You stated that "Standard C++ has no string
class". If all you are saying is that the class std::string is actually a
template, then so what? It's still part of the standard, and you still
create an instance of it just like any other class:

#include <string>
using std::string;

int main()
{
string strA(); // empty string
string strB = "something"; // copy of "something"
string* pstrA = new string("something"); // pointer to string containing
"something"
delete pstrA;
}

Your statement that C++ has no such class implies that "string" is not part
of standard C++, and that the OP ought not rely on it. But that's simply
wrong, if that was your intent. If your statement was simply that
std::string is technically a typedef for a template, then you might have
stated that explicitly, instead of simply declaring there was no such class.
(But in that case, why bother making the statement at all?)

-Howard



Jul 23 '05 #11

"Howard" <al*****@hotmail.com> wrote in message
news:zs*********************@bgtnsc04-news.ops.worldnet.att.net...

#include <string>
using std::string;

int main()
{
string strA(); // empty string


Not a string at all. A declaration of a function named
'strA()' which returns type 'string'.

Gotcha! :-)

-Mike
Jul 23 '05 #12

"Markus Moll" <mo**@rbg.informatik.tu-darmstadt.de> wrote in message
news:42**********************@newsread2.arcor-online.net...
Hi

ab*********@spambob.com wrote:
Standard C++ has no string class.


Not sure what you mean.


He means that he doesn't consider a class template
specialization to be a type. Why, I don't know.

-Mike
Jul 23 '05 #13
Abecedarian wrote:
The class std::string is most certainly part of the standard C++
language.
It's a template class. It's defined as:

typedef basic_string<char, char_traits<char>, allocator<char> >

string;

BTW, this is a class template.
Just because it's a template class, doesn't mean it's not a class!


It's not a class, it's a template with 3 template parameters.


std::basic_string is. std::string is not. The former is a class template,
the latter an instance of it, i.e. a class.

Jul 23 '05 #14
Rolf Magnus wrote:
std::basic_string is. std::string is not. The former is a class template, the latter an instance of it, i.e. a class.


class template, class template instantiation, class: 3 different
concepts in C++. Mix them and you create confusion.

Jul 23 '05 #15

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:_3*****************@newsread2.news.pas.earthl ink.net...

"Howard" <al*****@hotmail.com> wrote in message
news:zs*********************@bgtnsc04-news.ops.worldnet.att.net...

#include <string>
using std::string;

int main()
{
string strA(); // empty string


Not a string at all. A declaration of a function named
'strA()' which returns type 'string'.

Gotcha! :-)

-Mike


Touché! :-)

-Howard
Jul 23 '05 #16
ab*********@spambob.com (03 May 2005 12:47,
<11**********************@o13g2000cwo.googlegroups .com>) a écrit :
Rolf Magnus wrote:
std::basic_string is. std::string is not. The former is a class

template,
the latter an instance of it, i.e. a class.


class template, class template instantiation, class: 3 different
concepts in C++. Mix them and you create confusion.


they are obviously linked one with each other.
An instantiated class is a kind of class. It's a class that is
'generated' (proper term being instantiated) from a class template.
What confusion is there ? I find that crystal clear.

Some rules about templates can be complex, for instance you can come up with
very clever designs based on partial specializations.

But that does not put any confusion on the *use* of instantiated classes.

The error message might be longer, but a compiler is free to report error
about 'std::string' rather than
'std::basic_string<char, std::char_traits<char>, std::allocator<char> >' ,
if it were judged a benefit, and important enough, by the compiler vendor.

That's hardly an issue with the use of class templates in the standard
library.

--
Samuel
Jul 23 '05 #17

Gotcha! :-)

-Mike


Touchi! :-)

-Howard


Aarrgh...that was an accented e when I sent it..not it's an i. I hate
Outlook Express!
Jul 23 '05 #18
al*****@hotmail.com (03 May 2005 16:31,
<6X*********************@bgtnsc05-news.ops.worldnet.att.net>) a écrit :

Gotcha! :-)

-Mike
Touché! :-)


Aarrgh...that was an accented e when I sent it..not it's an i. I hate
Outlook Express!


if it's any comfort to you : it did show up as 'é' for me :)

(I think your message did not have a 'Content-Type' field, so newsreaders
assume default encoding. I expect many would assume latin-1)

--
Samuel
Jul 23 '05 #19
Samuel Krempp wrote:
Gotcha! :-)

-Mike

Touché! :-)

Aarrgh...that was an accented e when I sent it..not it's an i. I hate
Outlook Express!


if it's any comfort to you : it did show up as 'é' for me :)


For me, it didn't show up in his posting at all. It did show up in your
answer though, since your posting has a proper Content-Type field.
(I think your message did not have a 'Content-Type' field,
Yes, that field is missing in Howard's posting. But I think if the charset
is explicitly set in one of the configuration dialogs, even Outlook Express
is able to generate one. It just doesn't by default, which is rather
stupid.
so newsreaders assume default encoding. I expect many would assume
latin-1)


I have set mine to a default of utf-8.

Jul 23 '05 #20
ra******@t-online.de (03 May 2005 17:33,
<d5*************@news.t-online.com>) a écrit :
so newsreaders assume default encoding. I expect many would assume
latin-1)


I have set mine to a default of utf-8.


right, that's going to be more and more of a common default.
But aren't there still a few forums with policies against posting in UTF-8 ?

Also that explains why the 'é' was invisible for you : within ASCII text, it
makes the sequence of bytes invalid for UTF-8, so it caused an error when
reading the message, and the erroneus byte was ignored.

--
Samuel
PS : what's that "GNU Outlook Express 0.00.0000.0002" you're using ?
8)
Jul 23 '05 #21

ab*********@spambob.com schreef:
msalters wrote:
d...@excite.it wrote:
In the stroustrup C++ programming language (third edition) i can
find example like this:

string s1= "Hello";

So I imagine string is a standard class.


Actually, it's std::string: "class string in namespace std"


Standard C++ has no string class.


It has two.
See ISO 14882, section 21.2 String classes [lib.string.classes]

HTH,
Michiel Salters

Jul 23 '05 #22
msalters wrote:
ab*********@spambob.com schreef:
Standard C++ has no string class.


It has two.
See ISO 14882, section 21.2 String classes [lib.string.classes]


FYI, I was persuaded that there is almost no difference between a class
template instantiation and a 'real' class (i.e. a class without
template parameters) and that both constitute a class in C++.

::A::

Jul 23 '05 #23
Abecedarian wrote:
Rolf Magnus wrote:
std::basic_string is. std::string is not. The former is a class

template, the latter an instance of it, i.e. a class.

class template, class template instantiation, class: 3 different
concepts in C++.


I fail to see how a class template instantiation is not a class.
Jul 23 '05 #24
Maybe the information in my question was incomplete, so i want
include the entire header file I found in unixware systems. It doesn't
seem standard to me. And this doesn't permit to declar a string in this
way:

string varStr;

Infact the previous line generate error using my CC compiler.

Below the integral content of /usr/include/CC/string:

#ident "@(#)unixsrc:usr/src/common/lib/libC/string /main/uw7_nj/1"

// this is a dummy version of the new standard library <string> class,
// intended only to allow some of the new exception classes to work

#ifdef __cplusplus

#ifndef _STRING_CXX
#define _STRING_CXX

class string {
public:
string(const char* c) { s = c; }
const char* c_str() const { return s; }
private:
const char* s;
};

#endif

#endif

Jul 23 '05 #25
dj***@excite.it wrote:
Maybe the information in my question was incomplete, so i want
include the entire header file I found in unixware systems. It doesn't
seem standard to me.
It isn't.
And this doesn't permit to declar a string in this way:

string varStr;
Right.
// this is a dummy version of the new standard library <string> class,
// intended only to allow some of the new exception classes to work


Well, doesn't that comment give you a hint?

Jul 23 '05 #26
> I fail to see how a class template instantiation is not a class.

See how far this gets you:

namespace std {
class string;
}

#include <string>

Jul 23 '05 #27
friedlingu...@yahoo.com wrote:
I fail to see how a class template instantiation is not a class.


See how far this gets you:

namespace std {
class string;
}

#include <string>


Hey, you're going to be bashed ... ;-)

Jul 23 '05 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
16
by: Steve | last post by:
Hi Guys, I have a string which contains data elements separated by spaces. I also have a function which returns the number of characters from the beginning of the string for a given number of...
23
by: YinTat | last post by:
Hi, I learned C++ recently and I made a string class. A code example is this: class CString { public: inline CString(const char *rhs) { m_size = strlen(rhs);
19
by: Mike Tyka | last post by:
Hello community, i'm fairly new to using the STL but i've been experimenting a bit with it. I tried to derive a new class say MyString from string like so: class MyString: public string{...
10
by: cmk128 | last post by:
Hi I am going to implement a new string class for my os, do you have any idea to enhance of standard c++ string class? If compare c++ string class with CS++ CString class and java String class,...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
5
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
5
by: Ray | last post by:
Hi all, I am thinking of subclassing the standard string class so I can do something like: mystring str; .... str.toLower (); A quick search on this newsgroup has found messages by others
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.