Reading new lines from text files in c++

T

Tasha Darke

Hi,

I'm having a problem finding the answer to a problem I'm having. I'm
trying to read data for a neural network from a text file where the
inputs are on one line, and the expected output the next. I can read
the inputs no problem, but where I expect the program to move to the
next line it instead continues to read "white space" on the same line.

The text file looks something like this
-1 -1 0 .......... -7 0
0.80000

I see -7 and 0 going into the training data array, followed by a load
of 0s, and not 0.8. I'm using fscanf to grab the numbers out (I'll
admit to not being very proficient with C++, and yes this is for Uni
coursework), since all the documentation I've read indicates that
fscanf will jump whitespace (and I therefore assumed lines).

I'm evidently missing something major here, so any assistance/links
would be gratefully recieved.

If you need to see the code in progress, I will happily post.

Tasha
 
U

URPradhan

Hi

Are you amy be reading file with the help of while loop with a
condition of EOF or new line charater (may be) .. see (check) if ur
doing it by new line character ....
 
V

Victor Bazarov

Tasha said:
I'm having a problem finding the answer to a problem I'm having. I'm
trying to read data for a neural network from a text file where the
inputs are on one line, and the expected output the next. I can read
the inputs no problem, but where I expect the program to move to the
next line it instead continues to read "white space" on the same line.

The text file looks something like this
-1 -1 0 .......... -7 0
0.80000

I see -7 and 0 going into the training data array, followed by a load
of 0s, and not 0.8. I'm using fscanf to grab the numbers out (I'll
admit to not being very proficient with C++, and yes this is for Uni
coursework), since all the documentation I've read indicates that
fscanf will jump whitespace (and I therefore assumed lines).

I'm evidently missing something major here, so any assistance/links
would be gratefully recieved.

If you need to see the code in progress, I will happily post.

Don't offer. Read the FAQ 5.8 and follow its recommendations.

V
 
T

Tasha Darke

Whoops, sorry for not reading the FAQ properly. I'll be sure to follow
it next time I post.
Thanks for the pointers, I've managed to sort the problem out - I
wasn't opening the file correctly (binary instead of text mode).

Thanks again

Tasha
 
U

utab

Take a look at the standard getline() function and string streams in
C++ book, I guess you will find the answer, If I got that right

getline reads whole line excluding the newline character
and in brief you can extract the necessary information with string
streams I guess

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top