字符串类不标准 [英] string class not standard

查看:76
本文介绍了字符串类不标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在stroustrup C ++编程语言(第三版)中我可以

找到这样的例子:


string s1 =" Hello" ;;


所以我想象字符串是标准类。


此外,示例中的类初始化为

像这样的构造函数


string :: string();


奇怪的是:


在unixWare下我只使用这个

构造函数声明了字符串类:


string :: string(const char * c);


这似乎不是标准解决方案!怎么可能?


为什么unixware下的字符串文件包含一个类似的类?

无效的构造函数?


提前致谢


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

推荐答案

d ... @ excite.it写道:
d...@excite.it wrote:
在stroustrup中C ++编程语言(第三版)我可以找到这样的例子:

字符串s1 =" Hello" ;;

所以我想象字符串是标准类。


实际上,它是std :: string:"命名空间std中的类字符串"

此外,示例中的类初始化为<像这样的构造函数

string :: string();


奇怪的是:

在unixWare下我只用这个
构造函数声明了字符串类:

string :: string(const char * c);

这似乎不是标准的解决方案!怎么可能?
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?




因为它不是标准的std :: string,而是另一个

命名空间中的字符串?因为它早先被声明为

string :: string(const char * c = 0);并且实现有一个

c == 0的特殊情况?因为你错过了其他声明

(例如,副本ctor似乎也缺失了)


问候,

Michiel Salters



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写道:
msalters wrote:
d ... @ excite.it写道:
d...@excite.it wrote:
In stroustrup C ++编程语言(第三版)我可以找到这样的例子:

string s1 =" Hello" ;;

所以我想象字符串是一个标准类。
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.



实际上,它是命名空间std中的std :: string:"类字符串



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




标准C ++没有字符串类。



Standard C++ has no string class.


dj *** @ excite。它写道:
dj***@excite.it wrote:

在stroustrup C ++编程语言(第三版)中,我可以找到这样的例子:

string s1 =" Hello" ;;

所以我想象字符串是一个标准的clas秒。


是的,确实如此。在< string>中定义命名空间std中的标题。

此外,示例中的类使用
构造函数初始化

string :: string();


不,不是。首先,使用const char *中的转换

构造函数创建临时字符串,然后从中复制构造s1。

编译器可以省略临时并使用转换构造函数来直接构造s1 $

奇怪的是:

在unixWare下我只用这个
构造函数声明了字符串类:

string :: string(const char * c);

这个似乎不是标准解决方案!这怎么可能?


您使用的不是标准字符串类,或者您的标准

库实现已损坏。

为什么在unixware下使用字符串文件包含一个类似的类与
无效的构造函数?

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.


这篇关于字符串类不标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆