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 27 2202
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
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. 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.
<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
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.
<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 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?
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 ... ;-)
"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
"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
"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
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.
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.
"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 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 Gotcha! :-)
-Mike
Touchi! :-)
-Howard
Aarrgh...that was an accented e when I sent it..not it's an i. I hate
Outlook Express! 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
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. 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) 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
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::
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.
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 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?
> 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>
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 ... ;-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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);
|
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{...
|
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,...
|
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...
|
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
|
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...
|
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
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |