🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Steven J. Zeil Wed, 18 Oct 1995 18:36
Mandated char* in STD library
#2245
Author: 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. ]
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