Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Newline in a File Text file

Reply
Thread Tools

Newline in a File Text file

 
 
utab
Guest
Posts: n/a
 
      03-10-2006
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.

 
Reply With Quote
 
 
 
 
Dietmar Kuehl
Guest
Posts: n/a
 
      03-10-2006
utab wrote:
> 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>::ma x(), '\n');

This will skip all characters up to and including the next newline
character.
--
<private.php?do=newpm&u=> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
 
Reply With Quote
 
 
 
 
utab
Guest
Posts: n/a
 
      03-10-2006
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.

 
Reply With Quote
 
Dietmar Kuehl
Guest
Posts: n/a
 
      03-10-2006
utab wrote:
> 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.
--
<private.php?do=newpm&u=> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing tab and newline delimited text elsa Python 6 08-04-2010 06:34 AM
Display text with <newline> characters... TTT ASP .Net Web Controls 1 06-23-2006 12:14 AM
produce a newline for text output in XSLT Matt XML 2 11-02-2004 05:16 PM
Unicode and newline characters in XML text sond via Web Service Krzysztof Fink-Finowicki via .NET 247 ASP .Net Web Services 0 10-17-2004 10:04 AM
replace line #1 with "newline\n" in text file bmgz Python 5 12-25-2003 05:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57