Reading ifstream until predefined character

Hello all,

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
Last edited on
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
Use getline with an '=' delimiter. This will read everything up to and including the first = character.
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 '=')?
Last edited on
Ah, true...I'd probably get a whole line at a time then use string functions like find_first_of and substr to get the correct parts that you want.

I don't think there is a way to use multiple delimiters.
well, I did it and it actually worked, so problem solved (in 3 or 4 lines) =)

thx firedraco, thx bartoli
Topic archived. No new replies allowed.