C ++字符串终止 [英] C++ String termination
问题描述
我最近发现在std :: string a(some text),
a.length()== a.size ()。这是否意味着c ++字符串与c字符串不同,
不会被char(0)终止?出于某种原因,我曾经认为它们是。
~德米特里
Hi,
I recently found out that in std::string a("some text"),
a.length()==a.size(). Does that mean that c++ strings are, unlike c strings,
NOT terminated by char(0)? For some reason I used to think that they are.
~Dmitry
推荐答案
星期二,10 2004年2月23:52:53 GMT in comp.lang.c ++,Dmitry Denisenkov
< ca ********* @ SPAMyahoo.ca>据称写了:
On Tue, 10 Feb 2004 23:52:53 GMT in comp.lang.c++, "Dmitry Denisenkov"
<ca*********@SPAMyahoo.ca> was alleged to have written:
我最近发现在std :: string a(some text),
a.length()== a.size()。这是否意味着c ++字符串与c字符串不同,
不是以char(0)结尾?出于某种原因,我曾经认为它们是。
Hi,
I recently found out that in std::string a("some text"),
a.length()==a.size(). Does that mean that c++ strings are, unlike c strings,
NOT terminated by char(0)? For some reason I used to think that they are.
std :: string没有以''\0''或其他任何东西终止。
它可以包含零个字符而不受限制。 .c_str()成员
函数返回字符串内容的零终止版本,如果字符串包含任何零字符,则可能会产生混淆。
可能导致混淆。
std::string is not terminated with ''\0'' or anything else in particular.
It may contain zero characters without restriction. The .c_str() member
function returns a zero- terminated version of the string contents, with
potential for confusion if the string contains any zeros characters.
Dmitry Denisenkov写道:
Dmitry Denisenkov wrote:
我最近发现在std :: string a(some some" ),
a.length()== a.size()。这是否意味着c ++字符串与c字符串不同,
不是以char(0)结尾?出于某种原因,我曾经认为它们是。
〜德米特里
Hi,
I recently found out that in std::string a("some text"),
a.length()==a.size(). Does that mean that c++ strings are, unlike c strings,
NOT terminated by char(0)? For some reason I used to think that they are.
~Dmitry
我相信长度()和大小()是
字符串类的同义词。很多人都在讨论字符串的_length_文本,而其他人则谈论序列的_size_
或容器。因此两者都被提供并做同样的事情。
-
Thomas Matthews
C ++新闻组欢迎辞:
http://www.slack.net/~shiva /welcome.txt
C ++常见问题: http://www.parashift.com/c++-faq-lite
C常见问题: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c ++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
其他网站:
http://www.josuttis.com - C ++ STL图书馆书籍
http://www.sgi.com/tech/stl - 标准模板库
I do believe that length() and size() are synonyms for the
string class. Many people talk about the _length_ of a string
of text, while others talk about the _size_ of a sequence
or container. Thus both were provided and do the same thing.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
" Dmitry Denisenkov" < CA ********* @ SPAMyahoo.ca>在消息中写道
news:p9eWb.29694
"Dmitry Denisenkov" <ca*********@SPAMyahoo.ca> wrote in message
news:p9eWb.29694
这篇关于C ++字符串终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!