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

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds