🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Beman Dawes Fri, 22 Mar 1996 02:04
Re: A couple of questions about strings
#3769
Author: Beman Dawes
Date: Fri, 22 Mar 1996 02:04
26 lines
1687 bytes
 
>I'm probably beating a dead horse here, but I had a couple of
>questions about the strings class (at least, the one in the April WP).
>Specifically, there are two design decisions that I don't understand.
>
>a) Why does basic_string::copy() not also copy an ending '\0'? If
>there's some sort of good reason, why wasn't a function added that did
>this (perhaps basic_string::copy_null() or something)? I must say, it
>is very inconvenient to copy a string to a C-style array of chars with
>the current string class.

There is such a function - it is called c_str().

>b) I don't see any reason why basic_string::copy() is not a const
>function. Any particular reason for that one?

copy() is const in the current WP.


--Beman Dawes
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: A couple of questions about strings
#3817
Author: Rich Paul
Date: Tue, 26 Mar 1996 18:58
24 lines
1687 bytes
Beman Dawes wrote:
> 
> 
> >a) Why does basic_string::copy() not also copy an ending '\0'? If
> >there's some sort of good reason, why wasn't a function added that did
> >this (perhaps basic_string::copy_null() or something)? I must say, it
> >is very inconvenient to copy a string to a C-style array of chars with
> >the current string class.
> 
> There is such a function - it is called c_str().

well, to be equivilent, it would really be:

strncpy ( buffer, string::c_str(), x );
buffer[x] = 0;	// only if strlen(buffer > x), but it's not safe
		// to check that way, since strlening a non-termed 						
		// char[] is a bad thing
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads