Newline in a File Text file

U

utab

Dear all,

I have a text file in the form of

1 2 3 4 5 6
--------/--------/--------/--------/--------/--------/ (I just used /
to better explain the fields)

6 fields of 8 characters. I want to read lets say fields 4,5 and 6 and
then go to the begining of the newline which is in the same format. And
then I will test the first character of the newline with $ and if true
the read process will terminate. I can read fields by positioning the
file pointer with seekg() function. Is there a direct way to position
the file pointer to the start of a newline.

I tried things but all gone wrong, I could not solve the problem of
going to the start of the newline.

Any help is appreciated.

Thanks.
 
D

Dietmar Kuehl

utab said:
I tried things but all gone wrong, I could not solve the problem of
going to the start of the newline.

I'm not exactly clear what you want to do. Apparently you want to
skip all characters at some point until the start of the next line.
The easiest way to do just this is to use the 'ignore()' member of
'std::istream':

in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

This will skip all characters up to and including the next newline
character.
 
U

utab

Thanks first,

lets say I read field 3 and then I would like to go to the start of the
newline immediately. I think it is more clear now.
But I guess this is quite OK with what I would like to do.

Thanks.
 
D

Dietmar Kuehl

utab said:
lets say I read field 3 and then I would like to go to the start of the
newline immediately. I think it is more clear now.

Is it...? Well, then...

Using 'ignore()' as shown in my previous reply, you can skip all
characters and go the next newline. There is no way to kind of
"jump" there without having the library look at the characters
because the file does not have any knowledge about the structure
within. You might have some success with fixed record size when
using the "C" locale, i.e. when the characters are not encoded,
but I would personally rather have 'ignore()' for the next line
start.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top