🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Mandated char* in STD library

#2245
From: Steven J. Zeil
Date: Wed, 18 Oct 1995 18:36
45 lines
2218 bytes
As I understand the I/O library description in the Working Paper, the
following code will NOT be legal: 
    ...
    // Get file to process
    string fileName;
    cout << "Enter filename: " << flush;
    cin >> fileName;
    ifstream input (fileName);

    // Process file "input"
    ...
because the ifstream (and ofstream) constructors expect the filename
as a char* style string, rather than the string class from the
standard <string>.

To accomplish the above, it looks like I must change the input
declaration to
    ifstream input(fileName.c_str());

So far, this is the only place I've seen where the use of char* rather
than string is mandated for programs that work entirely within the C++
world, not trying to link to C routines.  

1) Are there others that I've missed? 
     [Of course, there are routines that return char*, but the
      string(const char*) constructor supplies an "automatic" 
      conversion in such cases.]  

2) Is this an oversight, or is there a rationale for avoiding "string"
   in these cases? 

This bothers me when I think of trying to teach C++. For the beginner,
the ability to use the string class seems like a significant
advantage. Having to teach both forms of character strings, and
lacking an intuitive rule for when one must abandon string and use
char* [e.g., by calling c_str()] is an annoying complication.

=================================
Steven Zeil
Old Dominion University
=================================
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <463d03$l88@maui.cc.odu.edu>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 18 Oct 95 18:36:57 GMT
Approved: fjh@cs.mu.oz.au
From: zeil@amon.cs.odu.edu (Steven J. Zeil)
Newsgroups: comp.std.c++
Subject: Mandated char* in STD library
X-Original-Date: 18 Oct 1995 17:20:03 GMT
Organization: Old Dominion University CS Dept.
Message-ID: <463d03$l88@maui.cc.odu.edu>
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMIVJVeEDnX0m9pzZAQEJNwF/c9UbcpZJ/XB/cPqbPDrZnhKTAPfeVYHQ
 fkRQvJSHJjRxeytEvIw7t51039Bp7q+g
 =XZLe