CString Extension for numerical IO | CodeGuru

CString Extension for numerical IO

I think it is fairly self explaining. I have added calls to put and get numerical entries into the string class by Zafir Anjum. This, with the parsing routines already included, have proven quite usefull at least to me. The following extentions add numerical reading and writting to the CStringEx Class. The default field length […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 14, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

I think it is fairly self explaining. I have added calls to put and get numerical entries
into the string class by Zafir Anjum. This, with the parsing routines already included, have
proven quite usefull at least to me.

The following extentions add numerical reading and writting to the CStringEx Class. The
default field length of 8 is used to support my application for Finite Element Card Immage
format of 10 fields of 8. Change as you desire. The original code is actually from the late
70’s and was in fortran. This is why some of the structure has evolved to the form that it
is now in.

The primary calls added are Put and Get functions for the major numerical types of int,
long, float and double. i.e. PutFloat() and GetFloat().

The core of two added functions PutFloatS and PutDoubleS were supplied by “Pierre Caussin
and Jean-Paul Retru”, Thanks. The change in these routines is the length specified is the
accuracy rather than the total length of the string.

One function you may wish to remove depending on your desires is the call to “Accuracy”.
This function sets the digits past 8 or 16 to zeros rather than the random numbers that
are default.

Primary added functions are

	int GetInt();
	long GetLong();
	float GetFloat();
	double GetDouble();
	void PutInt(int i, int len=8);
	void PutLong(long i, int len=8);
	void PutFloat(float f, int len=8);
	void PutDouble(double f, int len=8);
	void PutFloatS(float f, int len=8);
	void PutDoubleS(double f, int len=8);

Down load source and demo (VC6) – 27 KB

Updated on: April 14, 1999.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.