Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing for Data Type

Status
Not open for further replies.

One2b

Programmer
May 29, 2003
14
0
0
US
I have a text file which contains different types of data. I read in the text file into a CString and use it to parse information. However, I need to now get some of the data out, but some of it could be double, float, or int. I know of the functions like atoi, atof, etc. However, I need to first test what type it is before converting it from the CString to the data type. I was wondering if anyone knew of a way to test for what kind of data type you may be working with. If i just randomly convert then i may lose data along the way. Thx
 
>> I have a text file which contains different types of data.

The file should have a format specification so you know what data types are in what positions in the file. Do you not have the specification?

-pete
 
No...it can be any type of data. It stores values ranging from -3.3243425 to 2.000000 to 69901232873123, to -3.4, etc.
So therefore any of the files used with this parser may contain any type of data type, ranging from int, double, float...etc.
 
That is just not right [lol]

So if there is no specification for the file how do you know what the numbers represent? How do you use them? So you can create a collection of numbers by parsing the file then….. [bugeyed]

So you'll have to write a parser or use something you can find on the net. There are probably thousands of free parsers you can find.

You could consider not using float just double and long and test for the decimal point character to differentiate the two. But you still have to parse the data.


-pete
 
Well i have no problem parsing the data the way i need to. It is a lisp-style list and certain elements conatain data. If someone calls the convert function i want it to convert this specific element to the appropriate data type.
 
>> It is a lisp-style list and certain elements conatain data.

Oh, so there is a known format. That would have helped.

So maybe the Boost Regex library is all you need then.

Good luck

-pete
 
What is this Boost Regededx library you speak of?
 
Regular Expressions, if you search Google for that phrase you will find definitions of what they are.

[blue]
The Boost web site provides free peer-reviewed portable C++ source libraries. The emphasis is on libraries which work well with the C++ Standard Library. One goal is to establish "existing practice" and provide reference implementations so that the Boost libraries are suitable for eventual standardization. Some of the libraries have already been proposed for inclusion in the C++ Standards Committee's upcoming C++ Standard Library Technical Report.
[/blue]



-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top