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 | | | | re: string class not standard
d...@excite.it wrote:[color=blue]
> 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.[/color]
Actually, it's std::string: "class string in namespace std"
[color=blue]
> Furthermore the class in the example is initialized with a
> constructor like this
>
> string::string();[/color]
[color=blue]
> 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?[/color]
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 | | | | re: string class not standard
msalters wrote:[color=blue]
> d...@excite.it wrote:[color=green]
> > 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.[/color]
>
> Actually, it's std::string: "class string in namespace std"[/color]
Standard C++ has no string class. | | | | re: string class not standard djake@excite.it wrote:
[color=blue]
>
> 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.[/color]
Yes, it is. Defined in the <string> header in namespace std.
[color=blue]
> Furthermore the class in the example is initialized with a
> constructor like this
>
> string::string();[/color]
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.
[color=blue]
> 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?[/color]
Either you are using another than the standard string class or your standard
library implementation is broken.
[color=blue]
> Why under unixware the string file contain a similar class with
> invalid constructors?[/color]
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. | | | | re: string class not standard
<abecedarian@spambob.com> wrote in message
news:1115051850.839815.100250@f14g2000cwb.googlegr oups.com...[color=blue]
> msalters wrote:[color=green]
>> d...@excite.it wrote:[color=darkred]
>> > 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.[/color]
>>
>> Actually, it's std::string: "class string in namespace std"[/color]
>
> Standard C++ has no string class.[/color]
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 | | | | re: string class not standard
Hi abecedarian@spambob.com wrote:
[color=blue]
> Standard C++ has no string class.[/color]
Not sure what you mean.
Markus | | | | re: string class not standard
Mike Wahler wrote:[color=blue]
> <abecedarian@spambob.com> wrote in message[color=green]
> > Standard C++ has no string class.[/color]
>
> Certainly it does (its standard library does). It's declared
> (in namespace 'std') by standard header <string>.[/color]
Look into the header <string>. I bet you don't find a string class
there. | | | | re: string class not standard
<abecedarian@spambob.com> wrote in message
news:1115058822.083288.177890@g14g2000cwa.googlegr oups.com...[color=blue]
> Mike Wahler wrote:[color=green]
>> <abecedarian@spambob.com> wrote in message[color=darkred]
>> > Standard C++ has no string class.[/color]
>>
>> Certainly it does (its standard library does). It's declared
>> (in namespace 'std') by standard header <string>.[/color]
>
> Look into the header <string>. I bet you don't find a string class
> there.
>[/color]
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 | | | | re: string class not standard abecedarian@spambob.com wrote:
[color=blue]
> Mike Wahler wrote:[color=green]
>> <abecedarian@spambob.com> wrote in message[color=darkred]
>> > Standard C++ has no string class.[/color]
>>
>> Certainly it does (its standard library does). It's declared
>> (in namespace 'std') by standard header <string>.[/color]
>
> Look into the header <string>. I bet you don't find a string class
> there.[/color]
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? | | | | re: string class not standard
Howard wrote:[color=blue]
> <abecedarian@spambob.com> wrote in message
> news:1115058822.083288.177890@g14g2000cwa.googlegr oups.com...[color=green]
> > Mike Wahler wrote:[color=darkred]
> >> <abecedarian@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>.[/color]
> >
> > Look into the header <string>. I bet you don't find a string class
> > there.[/color]
>
> The class std::string is most certainly part of the standard C++[/color]
language.[color=blue]
> It's a template class. It's defined as:
>
> typedef basic_string<char, char_traits<char>, allocator<char> >[/color]
string;
BTW, this is a class template.
[color=blue]
> Just because it's a template class, doesn't mean it's not a class![/color]
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".
[color=blue]
> Check the standard if you don't believe it's part of the language.[/color]
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 ... ;-) | | | | re: string class not standard
"Abecedarian" <abecedarian@spambob.com> wrote in message
news:1115066462.468273.155130@z14g2000cwz.googlegr oups.com...[color=blue]
> Howard wrote:[color=green]
>> <abecedarian@spambob.com> wrote in message
>> news:1115058822.083288.177890@g14g2000cwa.googlegr oups.com...[color=darkred]
>> > Mike Wahler wrote:
>> >> <abecedarian@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.[/color]
>>
>> The class std::string is most certainly part of the standard C++[/color]
> language.[color=green]
>> It's a template class. It's defined as:
>>
>> typedef basic_string<char, char_traits<char>, allocator<char> >[/color]
> string;
>
> BTW, this is a class template.[/color]
Well, if you want to get technical, the above is just a typedef... an alias
to a template, in this case.
[color=blue]
>[color=green]
>> Just because it's a template class, doesn't mean it's not a class![/color]
>
> 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".
>[color=green]
>> Check the standard if you don't believe it's part of the language.[/color]
>
> But you just confirmed that there is no string class just a clumsy
> basic_string<char, char_traits<char>, allocator<char> > class template.
>[/color]
What's clumsy about it? Perhaps you're just not comfortable with templates?
[color=blue]
> Don't shoot the messenger ... ;-)[/color]
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 | | | | re: string class not standard
"Howard" <alicebt@hotmail.com> wrote in message
news:zsxde.173193$cg1.120473@bgtnsc04-news.ops.worldnet.att.net...[color=blue]
>
> #include <string>
> using std::string;
>
> int main()
> {
> string strA(); // empty string[/color]
Not a string at all. A declaration of a function named
'strA()' which returns type 'string'.
Gotcha! :-)
-Mike | | | | re: string class not standard
"Markus Moll" <moll@rbg.informatik.tu-darmstadt.de> wrote in message
news:42765d07$0$7516$9b4e6d93@newsread2.arcor-online.net...[color=blue]
> Hi
>
> abecedarian@spambob.com wrote:
>[color=green]
>> Standard C++ has no string class.[/color]
>
> Not sure what you mean.[/color]
He means that he doesn't consider a class template
specialization to be a type. Why, I don't know.
-Mike | | | | re: string class not standard
Abecedarian wrote:
[color=blue][color=green]
>> 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> >[/color]
> string;
>
> BTW, this is a class template.
>[color=green]
>> Just because it's a template class, doesn't mean it's not a class![/color]
>
> It's not a class, it's a template with 3 template parameters.[/color]
std::basic_string is. std::string is not. The former is a class template,
the latter an instance of it, i.e. a class. | | | | re: string class not standard
Rolf Magnus wrote:[color=blue]
> std::basic_string is. std::string is not. The former is a class[/color]
template,[color=blue]
> the latter an instance of it, i.e. a class.[/color]
class template, class template instantiation, class: 3 different
concepts in C++. Mix them and you create confusion. | | | | re: string class not standard
"Mike Wahler" <mkwahler@mkwahler.net> wrote in message
news:_3yde.3359$BE3.3000@newsread2.news.pas.earthl ink.net...[color=blue]
>
> "Howard" <alicebt@hotmail.com> wrote in message
> news:zsxde.173193$cg1.120473@bgtnsc04-news.ops.worldnet.att.net...[color=green]
>>
>> #include <string>
>> using std::string;
>>
>> int main()
>> {
>> string strA(); // empty string[/color]
>
> Not a string at all. A declaration of a function named
> 'strA()' which returns type 'string'.
>
> Gotcha! :-)
>
> -Mike[/color]
Touché! :-)
-Howard | | | | re: string class not standard abecedarian@spambob.com (03 May 2005 12:47,
<1115117230.050533.280500@o13g2000cwo.googlegroups .com>) a écrit :
[color=blue]
> Rolf Magnus wrote:[color=green]
>> std::basic_string is. std::string is not. The former is a class[/color]
> template,[color=green]
>> the latter an instance of it, i.e. a class.[/color]
>
> class template, class template instantiation, class: 3 different
> concepts in C++. Mix them and you create confusion.[/color]
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 | | | | re: string class not standard
[color=blue][color=green]
>>
>> Gotcha! :-)
>>
>> -Mike[/color]
>
> Touchi! :-)
>
> -Howard
>
>[/color]
Aarrgh...that was an accented e when I sent it..not it's an i. I hate
Outlook Express! | | | | re: string class not standard alicebt@hotmail.com (03 May 2005 16:31,
<6XLde.692433$w62.273712@bgtnsc05-news.ops.worldnet.att.net>) a écrit :
[color=blue]
>[color=green][color=darkred]
>>>
>>> Gotcha! :-)
>>>
>>> -Mike[/color]
>>
>> Touché! :-)[/color][/color]
[color=blue]
>
> Aarrgh...that was an accented e when I sent it..not it's an i. I hate
> Outlook Express![/color]
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 | | | | re: string class not standard
Samuel Krempp wrote:
[color=blue][color=green][color=darkred]
>>>> Gotcha! :-)
>>>>
>>>> -Mike
>>>
>>> Touché! :-)[/color][/color]
>[color=green]
>>
>> Aarrgh...that was an accented e when I sent it..not it's an i. I hate
>> Outlook Express![/color]
>
> if it's any comfort to you : it did show up as 'é' for me :)[/color]
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.
[color=blue]
> (I think your message did not have a 'Content-Type' field,[/color]
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.
[color=blue]
> so newsreaders assume default encoding. I expect many would assume
> latin-1)[/color]
I have set mine to a default of utf-8. | | | | re: string class not standard ramagnus@t-online.de (03 May 2005 17:33,
<d5857i$trt$04$1@news.t-online.com>) a écrit :
[color=blue][color=green]
>> so newsreaders assume default encoding. I expect many would assume
>> latin-1)[/color]
>
> I have set mine to a default of utf-8.[/color]
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) | | | | re: string class not standard abecedarian@spambob.com schreef:[color=blue]
> msalters wrote:[color=green]
> > d...@excite.it wrote:[color=darkred]
> > > 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.[/color]
> >
> > Actually, it's std::string: "class string in namespace std"[/color]
>
> Standard C++ has no string class.[/color]
It has two.
See ISO 14882, section 21.2 String classes [lib.string.classes]
HTH,
Michiel Salters | | | | re: string class not standard
msalters wrote:[color=blue]
> abecedarian@spambob.com schreef:[color=green]
> > Standard C++ has no string class.[/color]
>
> It has two.
> See ISO 14882, section 21.2 String classes [lib.string.classes][/color]
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:: | | | | re: string class not standard
Abecedarian wrote:
[color=blue]
> Rolf Magnus wrote:[color=green]
>> std::basic_string is. std::string is not. The former is a class[/color]
> template, the latter an instance of it, i.e. a class.
>
> class template, class template instantiation, class: 3 different
> concepts in C++.[/color]
I fail to see how a class template instantiation is not a class. | | | | re: string class not standard
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 | | | | re: string class not standard djake@excite.it wrote:
[color=blue]
> 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.[/color]
It isn't.
[color=blue]
> And this doesn't permit to declar a string in this way:
>
> string varStr;[/color]
Right.
[color=blue]
> // this is a dummy version of the new standard library <string> class,
> // intended only to allow some of the new exception classes to work[/color]
Well, doesn't that comment give you a hint? | | | | re: string class not standard
> 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> | | | | re: string class not standard
friedlingu...@yahoo.com wrote:[color=blue][color=green]
> > I fail to see how a class template instantiation is not a class.[/color]
>
> See how far this gets you:
>
> namespace std {
> class string;
> }
>
> #include <string>[/color]
Hey, you're going to be bashed ... ;-) |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,501 network members.
|