Thread View: comp.std.c++
2 messages
2 total messages
Started by Jamshid Afshar
Thu, 29 Feb 1996 18:49
wchar_t version of atof() and atoi()?
Author: Jamshid Afshar
Date: Thu, 29 Feb 1996 18:49
Date: Thu, 29 Feb 1996 18:49
42 lines
2434 bytes
2434 bytes
I'm new to internationalization issues but it's my understanding that
Standard C++ will have very good support for it by way of the
wide-character wstring and wifstream, etc. classes. For example, a
C++ program written in an environment that supports Unicode would
strictly use wstring, wifstream, and wchar_t in place of string,
ifstream, and char [1]. But, I didn't see a wchar_t* overload of
functions like strtod() or atoi(). How are strings (eg, entered by a
user into an edit box) supposed to be converted to numeric values in
an internationalized C++ program?
I would do something like:
int atoi( const wstring& s ) {
wistringstream strm(s);
int r;
s >> r;
if (s) return r;
else throw some_exception();
}
But stream i/o interprets "045" as an octal value instead of 45.
Also, it seems that if you want to write code that is portable to
either a Unicode compiler/environment or a regular single-byte string
environment you would have to introduce your own conditional typedefs
for the string and stream classes, and consistently use those typdefs
instead of directly using "string" or "wstring". Does that sound
right, or is there a technique using namespaces to solve this problem?
[1] It seems there's even "w" versions of the cin/cout (win/wout) and
the argv char*'s are allowed to be multi-byte character strings which
can be converted to wchar_t strings.
Jamshid Afshar
jamshid@io.com
---
[ 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
]
Re: wchar_t version of atof() and atoi()?
Author: J. Kanze
Date: Mon, 04 Mar 1996 12:49
Date: Mon, 04 Mar 1996 12:49
48 lines
2610 bytes
2610 bytes
In article <4h4oiv$4md@xanadu.io.com> jamshid@io.com (Jamshid Afshar)
writes:
|> I'm new to internationalization issues but it's my understanding that
|> Standard C++ will have very good support for it by way of the
|> wide-character wstring and wifstream, etc. classes. For example, a
|> C++ program written in an environment that supports Unicode would
|> strictly use wstring, wifstream, and wchar_t in place of string,
|> ifstream, and char [1]. But, I didn't see a wchar_t* overload of
|> functions like strtod() or atoi(). How are strings (eg, entered by a
|> user into an edit box) supposed to be converted to numeric values in
|> an internationalized C++ program?
Using a wchar_t version of istringstream, I suppose. In general, very
little has been done with regards to the various functions inherited
from C that operated on char* or const char*; it is expected that most
C++ programs will use string and iostream.
|> I would do something like:
|> int atoi( const wstring& s ) {
|> wistringstream strm(s);
|> int r;
===> s.setf( ios::dec , ios::basefield) ;
|> s >> r;
|> if (s) return r;
|> else throw some_exception();
|> }
|> But stream i/o interprets "045" as an octal value instead of 45.
Insert the specified line. On creation, the basefield is 0, which has
the behavior you describe.
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
-- A la recherche d'une activiti dans une region francophone
---
[ 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.
]
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