I am programming a circuit simulator that reads PSPICE netlists...well, so the program basically reads a netlist, a text file by ifstream >> thing and I have a problem here:
There are 4 possible cases, I have to read 20e-10, for example, in the 5 cases:
1) there is a 'IC = 20e-10" in the file
2) there is a 'IC= 20e-10" in the file
3) there is a 'IC=20e-10' in the file
4) there is a 'IC =20e-10' in the file
5) there is a '20e-10' without IC= in the file
if I could read until the '=' char and then read the next double (separated or not by space) then my problem would be solved...I need to do it in a simple way
I'd really appreciate any advice, I'd like to do it in the cleanest way
Thanks in advance,
Guilherme
You could read a full line, then remove all the spaces. Then you look backwards for '=', and pass what is after (or from the start if it was not found) to a function that will convert the number from string to double. The removal of the spaces might even be optionnal depending on how the number conversion function you choose works
using getline with '=' delimiter is a good idea, but there is also the case 5, if I use getline in a pspice file as the number 5 then the file pointer would be sent to the end of the file...
would it be possible to use a getline with 2 delimiters at the same time ('\n' and '=')?