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

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds