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: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds