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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds