I have a variable stringthat can be one of three things:
- Number
- Number in scientific notation
- Text
In cases 1 and 3, I want to do nothing and transmit data. But in case 2, I need to convert it to a regular number. If I just always convert a variable to a regular number, then when it contains the actual text, it becomes "0". So I need to know if a string is a number in scientific notation. The obvious, dirty answer is this algorithm:
Iterate over the line until you see the numbers. If the first letter you see is "e" or "E", followed by either "+", or "-", or strictly more numbers, then this is a number in scientific notation, otherwise it is just a regular number or text.
But I assume that there is a better way to do this in C ++ 98 (without promotion). Is there a built-in method? Even if it is something that just uses try / catch.
EDIT The question was closed because it was supposed to be homework. This is not homework. Therefore, it should be renewed. Also, to clarify, I am forced to use C ++ 98 due to technical limitations.
, ( "" , ). , .
, :
1.453e-8
0.05843E5
8.43e6
5.2342E-7
, :
hello
03HX_12
8432
8432E
e-8
fail-83e1
