473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Newline in a File Text file

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.

Mar 10 '06 #1
3 2843
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.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Mar 10 '06 #2
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.

Mar 10 '06 #3
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.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Mar 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Charles Erwin | last post by:
Is there any way, upon scanning in a file line by line to avoid missing the last line if there is not a newline character (aka you have to hit return on the last line of input in your file). I was...
16
by: John Smith | last post by:
Hi all Why doesn't this seem to work? void stripnl(char *sz) { char *nl; nl = strchr(sz, '\n'); if (nl) {
0
by: Quan Nguyen | last post by:
StreamWriter sw = new StreamWriter(strFileName, false, encoding); sw.NewLine = "\r\n"; sw.Write(txtbox.Text); sw.Close(); In the code snippet above, I tried to save the content of a...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
7
by: Alex Nordhus | last post by:
I am looking for a way to strip the blank line and the empty newline at the end of the text file. I can get the blank lines removed from the file but it always leaves the end line (which is blank)...
1
by: utab | last post by:
Hi there I am trying to read from a file, I am trying to read certain fields,there are 6 fields in this file like --------/--------/--------/--------/--------/--------/ All fields are 8...
1
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
4
by: Florian Lindner | last post by:
Hello, I have a piece of code like that: for row in resultSet: logs += "/home/%s/%s/log/access.log \n" % (row, row) logs += "/home/%s/%s/log/error.log \n" % (row, row) # <-- Now I want to...
0
by: Peter Donis | last post by:
When running a doctest text file with doctest.testfile, I noticed that universal newline support did not appear to work when module_relative is False. My text file was saved on a Windows machine...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.