🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

wchar_t version of atof() and atoi()?

#3555
From: Jamshid Afshar
Date: Thu, 29 Feb 1996 18:49
42 lines
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 
]
Technical Details
Message-ID: <4h4oiv$4md@xanadu.io.com>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: jamshid@io.com (Jamshid Afshar)
Newsgroups: comp.std.c++
Subject: wchar_t version of atof() and atoi()?
Date: 29 Feb 1996 10:49:07 PST
Organization: Illuminati Online, Austin, Texas, USA
Approved: austern@isolde.mti.sgi.com
Message-ID: <4h4oiv$4md@xanadu.io.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 29 Feb 1996 11:42:55 -0600
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMTX1Nky4NqrwXLNJAQFkCAH/Wioo/VM3QBboBRbX72nW0j3UZQLJrddI
 fcEpmwR7xlsr4lQPmDdUMruHDGA5SbIb1V9cpkyPE9dL6nmxOadPmw==
 =07sL
Originator: austern@isolde.mti.sgi.com