🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1720

Re: Why no conversion of string to const char * in STD lib?

#1720
From: Rick Hollinbeck
Date: Sun, 13 Aug 1995 23:11
28 lines
1536 bytes
Don & (bashford@toad.scripps.edu) wrote:
: According to Plauger's book on the Draft Standard C++ library,
: there is no "operator const char *" for the string class.
: This means that you cannot do things like,

:   string filename;
:   // ...
:   ofstream ofile(filename);

: Alot of my code has things like this (I have been using the
: String class of libg++) and I suspect this is rather common
: apparently we will all have to change to:

:   ofstream ofile(filename.c_str());

: which will be incompatable with any other string class that
: does not have a c_str function (String of libg++ does not).

: Is there any compelling reason for not having the conversion
: to const char* as part of the standard?

: Don Bashford
: bashford@scripps.edu

>From what I understand, the const char* conversion operator would trigger
too many implicit type conversions in certain situations, leading to many
unpleasant surprises. the c_str() member is a way to control this. (See
Plauger's recent article in the C/C++ Users Journal which discusses this.)
Technical Details
Message-ID: <MATT.95Aug13161131@physics2.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <BASHFORD.95Aug1200815@toad.scripps.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: rickh@csn.net (Rick Hollinbeck)
Newsgroups: comp.std.c++
Subject: Re: Why no conversion of string to const char * in STD lib?
Date: 13 Aug 1995 23:11:31 GMT
Organization: SuperNet Inc. (303)-296-8202 Denver Colorado
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Aug13161131@physics2.Berkeley.EDU>
References: <BASHFORD.95Aug1200815@toad.scripps.edu>
NNTP-Posting-Host: physics2.berkeley.edu