473,398 Members | 2,389 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,398 software developers and data experts.

string constructor difference

Hi

Could any one tell me the difference between these 2 string
constructors ?

1)string( const char* str );

2)string( const char* str, size_type length );

A reference
http://www.cppreference.com/cppstrin...structors.html says
that second one creates "a duplicate of str (optionally up to length
characters long)".Why is the word optionally used there. Does this mean
that if a '\0' appears in the character array the copying will
end there ?
Thanks
Kiran.

Aug 7 '06 #1
2 1458
wolverine wrote:
Could any one tell me the difference between these 2 string
constructors ?

1)string( const char* str );

2)string( const char* str, size_type length );

A reference
http://www.cppreference.com/cppstrin...structors.html says
that second one creates "a duplicate of str (optionally up to length
characters long)".Why is the word optionally used there.
Because the clowns who wrote this "reference" couldn't spring for one
extra description to separate the two constructors. BTW, in some of
those constructors there is also one more argument - the allocator.
Does this
mean that if a '\0' appears in the character array the copying will
end there ?
I don't know what this means. The constructor of the standard 'string'
class that has three arguments:

strint(char const* str, size_type n, Allocator const &a = Allocator())

will NOT stop if it encounters a null character. It will copy exactly
'n' characters from the array the first element of which is pointed to
by 'str'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 7 '06 #2
Victor Bazarov wrote:
wolverine wrote:
Could any one tell me the difference between these 2 string
constructors ?

1)string( const char* str );

2)string( const char* str, size_type length );

A reference
http://www.cppreference.com/cppstrin...structors.html says
that second one creates "a duplicate of str (optionally up to length
characters long)".Why is the word optionally used there.

Because the clowns who wrote this "reference" couldn't spring for one
extra description to separate the two constructors. BTW, in some of
those constructors there is also one more argument - the allocator.
Does this
mean that if a '\0' appears in the character array the copying will
end there ?

I don't know what this means. The constructor of the standard 'string'
class that has three arguments:

strint(char const* str, size_type n, Allocator const &a = Allocator())

will NOT stop if it encounters a null character. It will copy exactly
'n' characters from the array the first element of which is pointed to
by 'str'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Thanks Victor.
Your answer cleared my doubt partially.

Aug 8 '06 #3

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

Similar topics

5
by: Doug Goulden | last post by:
I have an application library that I have been using for some time with no problems. Yesterday though I started to use part of the library and found that the results were much different than I...
31
by: Peter Michaux | last post by:
Hi, I want to know the name of an object's constructor function as a string. Something like this <script type="text/javascript"> function Foo(){}; var a = new Foo(); alert('"' +...
7
by: dragoncoder | last post by:
Hello experts, I have the following code me. =cat mystring.h #include<iostream> using namespace std; class mystring {
10
by: abhash | last post by:
I am bit puzzled at the following piece of code I tried: ---------------------------------------------------------------------------------- #include <iostream> using namespace std; class Test...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.