<HTML><HEAD><TITLE>N1802=05-0062, Uniform Use of <CODE>std::string</CODE></TITLE></HEAD><BODY>

<CENTER>
<H1><A NAME="Uniform Use of <CODE>std::string</CODE>">Uniform Use of <CODE>std::string</CODE></A></H1>
</CENTER>

<TABLE ALIGN="RIGHT" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="RIGHT"><B><I>Document number:</I></B></TD>
<TD>&nbsp; N1802=05-0062</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Date:</I></B></TD>
<TD>&nbsp; 2005-04-18</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Project:</I></B></TD>
<TD>&nbsp; Programming Language C++</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reference:</I></B></TD>
<TD>&nbsp; ISO/IEC IS 14882:2003(E)</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reply to:</I></B></TD>
<TD>&nbsp; Pete Becker</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; Dinkumware, Ltd.</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; petebecker@acm.org</TD>
</TR>
</TABLE>
<BR CLEAR="ALL">

<HR>

<H2><A NAME=Introduction>Introduction</H2>

<P>There are seventeen places in the C++ Standard Library where we use <CODE>char*</CODE>
strings in the interface; in each of these places we can add an overload that takes
an object of type <CODE>std::string</CODE>.</P>

<H2><A NAME=Proposed Wording>Proposed Wording</H2>

<P>In [lib.locale], 22.1.1, add the following constructors:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit locale(string <I>std_name</I>);
locale(const locale&amp; <I>other</I>, string <I>std_name</I>, category);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.cons], 22.1.1.2, after the entry for <CODE>explicit locale(const
char * <I>std_name</I>)</CODE>, add the following:

<BLOCKQUOTE>
<PRE><CODE>explicit locale(string <I>std_name</I>);</CODE></PRE>

<I>Effects:</I> the same as <CODE>locale(std_name.c_str())</CODE>.
</BLOCKQUOTE>

<P>In [lib.locale.cons], 22.1.1.2, after the entry for <CODE>locale(const locale&amp;
<I>other</I>, const char* <I>std_name</I>, category)</CODE>, add the following:

<BLOCKQUOTE>
<PRE><CODE>locale(const locale&amp; <I>other</I>, string <I>std_name</I>, category <I>cat</I>);</CODE></PRE>

<I>Effects:</I> the same as <CODE>locale(other, std_name.c_str(), cat)</CODE>.
</BLOCKQUOTE>

<P>In [lib.locale.facet], 22.1.1.1.2, paragraph 4, after the sentence "Each such facet
provides a constructor that takes a <CODE>const char*</CODE> argument, which names
the locale, and a <I>refs</I> argument, which is passed to the base class constructor"
add the following sentence:</P>

<BLOCKQUOTE>
Each such facet also provides a constructor that takes a <CODE>string</CODE> argument
<I>str</I> and a <I>refs</I> argument, which has the same effect as calling the first
constructor with the two arguments <CODE>str.c_str()</CODE> and <CODE>refs</CODE>.
</BLOCKQUOTE>

<P>In [lib.locale.ctype.byname], 22.2.1.2, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit ctype_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.codecvt.byname], 22.2.1.5, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit codecvt_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.numpunct.byname], 22.2.3.2, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit numpunct_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.collate.byname], 22.2.4.2, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit collate_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.time.get.byname], 22.2.5.2, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit time_get_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.time.put.byname], 22.2.5.4, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit time_put_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.moneypunct.byname], 22.2.6.4, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit moneypunct_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.locale.messages.byname], 22.2.7.2, after the declaration of the constructor, add the
following constructor:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit messages_byname(string, size_t <I>refs</I> = 0);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.filebuf], 27.8.1.1, add the following declaration after the declaration of
the member function <CODE>open</CODE>:

<BLOCKQUOTE>
<PRE><CODE>basic_filebuf<charT,traits> *open(string <I>s</I>, ios_base::openmode <I>mode</I>);</CODE></PRE>
</BLOCKQUOTE>

<P>In [lib.filebuf.members], 27.8.1.3, add the following after paragraph 5:</P>

<BLOCKQUOTE>
<PRE><CODE>basic_filebuf<charT,traits> *open(string <I>s</I>, ios_base::openmode <I>mode</I>);</CODE></PRE>

<P><I>Returns:</I> <CODE>open(s.c_str(), mode);</CODE></P>
</BLOCKQUOTE>

<P>In [lib.ifstream], 27.8.1.5, add the following declarations to the declaration of
<CODE>basic_ifstream</CODE>:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit basic_ifstream(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::in);
void open(string <I>s</I>, ios_base::openmode <I>mode</I> = ios_base::in);</CODE></PRE>
</BLOCKQUOTE>

<P>At the end of [lib.ifstream.cons], 27.8.1.6, add the following:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit basic_ifstream(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::in);</CODE></PRE>

<P><I>Effects:</I> the same as <CODE>basic_ifstream(s.c_str(), mode);</CODE></P>
</BLOCKQUOTE>

<P>In [lib.ifstream.members], 27.8.1.7, after the entry for <CODE>open</CODE>, add
the following:</P>

<BLOCKQUOTE>
<PRE><CODE>void open(string <I>s</I>, ios_base::openmode <I>mode</I> = ios_base::in);</CODE></PRE>
</BLOCKQUOTE>

<P><I>Effects:</I> calls <CODE>open(s.c_str(), mode);</CODE></P>

<P>In [lib.ofstream], 27.8.1.8, add the following declarations to the declaration of
<CODE>basic_ofstream</CODE>:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit basic_ofstream(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::out);
void open(string <I>s</I>, ios_base::openmode <I>mode</I> = ios_base::out);</CODE></PRE>
</BLOCKQUOTE>

<P>At the end of [lib.ofstream.cons], 27.8.1.9, add the following:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit basic_ofstream(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::out);</CODE></PRE>

<P><I>Effects:</I> the same as <CODE>basic_ofstream(s.c_str(), mode);</CODE></P>
</BLOCKQUOTE>

<P>In [lib.ofstream.members], 27.8.1.10, after the entry for <CODE>open</CODE>, add
the following:</P>

<BLOCKQUOTE>
<PRE><CODE>void open(string <I>s</I>, ios_base::openmode <I>mode</I> = ios_base::out);</CODE></PRE>
</BLOCKQUOTE>

<P><I>Effects:</I> calls <CODE>open(s.c_str(), mode);</CODE></P>

--------------------------------

<P>In [lib.fstream], 27.8.1.11, add the following declarations to the declaration of
<CODE>basic_fstream</CODE>:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit basic_fstream(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::in | ios_base::out);
void open(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::in | ios_base::out);</CODE></PRE>
</BLOCKQUOTE>

<P>At the end of [lib.fstream.cons], 27.8.1.12, add the following:</P>

<BLOCKQUOTE>
<PRE><CODE>explicit basic_fstream(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::in | ios_base::out);</CODE></PRE>

<P><I>Effects:</I> the same as <CODE>basic_fstream(s.c_str(), mode);</CODE></P>
</BLOCKQUOTE>

<P>In [lib.fstream.members], 27.8.1.13, after the entry for <CODE>open</CODE>, add
the following:</P>

<BLOCKQUOTE>
<PRE><CODE>void open(string <I>s</I>,
    ios_base::openmode <I>mode</I> = ios_base::in | ios_base::out);</CODE></PRE>
</BLOCKQUOTE>

<P><I>Effects:</I> calls <CODE>open(s.c_str(), mode);</CODE></P>

<HR>

</BODY></HTML>
