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 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.



Comments

  • You should first summarize what the code does.

    Posted by Legacy on 04/22/1999 12:00am

    Originally posted by: Bob Waber

    It would be helpful if you gave a short summary of what this code does and what it is useful for, rather that making everyone download and read the code before they can find out.

    Reply
  • Even easier...

    Posted by Legacy on 04/21/1999 12:00am

    Originally posted by: Stephane Stolz

    You can make the whole thing a lot easier by using the C++ operators instead of Set/Put type functions.
    
    declare the operator int() instead of GetInt() and operator =(int nValue) instead of PutInt and apply that to your other data types.

    Instead of writing code such as:
    int a=string.GetInt();

    you can write:
    int a=string;

    And vice versa, string.PutInt(a) becomes string = a;
    You can further extend the power of operators by defining a operator ==(int nValue) so you can actually have:
    if(string == nValue)
    {
    ...
    }

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds