reading from a text file

Jun 12, 2009 at 12:52am
One question...

I have a text file like:

DATA1=0;

What would be a way to look for "DATA1=" and return the value inmediately next...?

Jun 12, 2009 at 1:01am
Get the line into the string, then you would have to search for the = and then either return whatever is after that, or convert it to an int/whatever and return it.
Jun 12, 2009 at 4:42am
Pardon my ignorance but, while it does sound easy, I still fail to do it correctly...
Jun 12, 2009 at 7:20am
closed account (S6k9GNh0)
@ firedraco: Boy was that incomplete. :/

@ Alexandro: Since I've given an example about 10 times for this very specific job, I will not show you code. However, I will mention that there are examples all over this forum concerning this and there are containers inside of the Standard Library that will help you accomplish this called the 'ifstream'. The task you need to accomplish goes like this:

Declare buffer
Read file into buffer
Interpret buffer
Free buffer (depends on your buffer)
Last edited on Jun 12, 2009 at 7:26am
Jun 12, 2009 at 2:13pm
Well, then perhaps you could give OP some specific string you remember from your posts so he can search for them.
Jun 12, 2009 at 5:12pm
I thought fd's post was succinct and complete. Just looking at the string class methods should be enough to get that far.
Topic archived. No new replies allowed.