473,799 Members | 2,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Whitespace separating lines using extraction operator on file

Okay, i've got a file open, call it infile. I've got a simple while(!eof),
but say the first line of my file is "<?xml version="1.0">" , then it takes
two iterations to get the string. first 'line' is "<?xml", then 'line' is
"version="1.0"" , what's happening that I need to change the behavior of so
that I can get lines delimitted by the newlines in the file?

std::string line;
std::ifstream infile("whateve r.txt", std::ios_base:: in);
while(!infile.e of())
{
infile >> line;
std::cout << line << std::endl;
line = "";
}
infile.close();

Thanks for your time,
Kevin Grigorenko
Jul 19 '05
18 2583
"Buster Copley" <bu****@none.co m> wrote in message
news:bk******** **@newsg3.svr.p ol.co.uk...
Kevin Grigorenko wrote:
It is also quite interesting that whenever someone like myself makes these kinds of comments, people like yourself always reply as you have above, even though the reason they might have given a response as the first one that you gave is to "improve the signal-to-noise ratio." This sure looks like a lot of noise to me?!

That's really interesting. Do go on.


All I'm saying is that I disagree with "Please don't give them the location
of the appropriate FAQ." If you had just given me where to start in the FAQ
I would have not written the reply that I wrote. Point people to where they
need to go OR the GENERAL direction and then they will figure the rest out.
To point them nowhere as you did is what I consider noise on the board.

Kevin Grigorenko
Jul 19 '05 #11
Kevin Grigorenko wrote:
<snip>

You seem to have gotten your answer. Do you really feel it's wise to now
engage in a flame war with another member of the group who did nothing
out of line? Tempting regulars to killfile you is usually not a good
idea, if you hope for the group to be a useful resource.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #12
Kevin Grigorenko wrote:
All I'm saying is that I disagree with "Please don't give them the location
of the appropriate FAQ." If you had just given me where to start in the FAQ
I would have not written the reply that I wrote. Point people to where they
need to go OR the GENERAL direction and then they will figure the rest out.
To point them nowhere as you did is what I consider noise on the board.

Yes, I quite see your point. And you can be quite charming, when you put
your mind to it. I'll certainly consider what you have said.

Regards,
Buster.

Jul 19 '05 #13
[...]
Please in the future read the FAQ before posting. That's basic
Netiquette. (Honestly, I don't expect people to read the whole thing...
it's quite long. But you should at least try to locate your answer there
first.)

I actually did, I went there and found nothing blatantly related to my
question, so I posted it here.

[...]
I can't actually find the exact entry right now. What you want is


[...]

It's funny you mention that, I can't either! I did a search for getline on
the FAQ, and it's not there.

Buster Copley, can you please point me to where the use of getline can be
found in the FAQ (this is not meant to by sarcastic in anyway, and if Buster
does, then good for him, but if he doesn't then that means his baseline for
his complete argument is completely false).

Thanks,
Kevin Grigorenko
Jul 19 '05 #14
"Kevin Goodsell" <us************ *********@never box.com> wrote in message
news:oW******** *********@newsr ead4.news.pas.e arthlink.net...
Kevin Grigorenko wrote:
<snip>

You seem to have gotten your answer. Do you really feel it's wise to now
engage in a flame war with another member of the group who did nothing
out of line? Tempting regulars to killfile you is usually not a good
idea, if you hope for the group to be a useful resource.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


Listen, I'm sorry, I tried to be nice during this whole thing and provide
logical arguments. The simple fact is that I find some regular posters here
to be so audacious with some of their posts, it helps nobody. I can't even
find the FAQ that buster alluded to. Why can't we just be a community and
help each other. I've wasted just as much of my time as everyone else's
writing all of these posts. I probably just could have done a search on
google and found my answer, but I thought, "Hey, it's a pretty simple
question, i'm sure someone can answer it or point my in the right
direction." I just found Buster's reply to my post to be very
disrespectful, irregardless of the fact that it complied perfectly with the
netiquette as written on the FAQ.

Help each other out!

Kevin Grigorenko
Jul 19 '05 #15
Kevin Grigorenko wrote:
I can't actually find the exact entry right now. What you want is

[...]
It's funny you mention that, I can't either! I did a search for getline on
the FAQ, and it's not there.

Buster Copley, can you please point me to where the use of getline can be
found in the FAQ (this is not meant to by sarcastic in anyway, and if Buster
does, then good for him, but if he doesn't then that means his baseline for
his complete argument is completely false).

You're right, I was wrong. But I think if you reread the thread, most of
the argument was down to you. After I misdirected you to the FAQ, mostly
I was just commenting on your attitude problem.

Fire away,
Buster.

Jul 19 '05 #16
"Buster Copley" <bu****@none.co m> wrote in message
news:bk******** **@news6.svr.po l.co.uk...
Kevin Grigorenko wrote:
I can't actually find the exact entry right now. What you want is

[...]
It's funny you mention that, I can't either! I did a search for getline on the FAQ, and it's not there.

Buster Copley, can you please point me to where the use of getline can be found in the FAQ (this is not meant to by sarcastic in anyway, and if Buster does, then good for him, but if he doesn't then that means his baseline for his complete argument is completely false).

You're right, I was wrong. But I think if you reread the thread, most of
the argument was down to you. After I misdirected you to the FAQ, mostly
I was just commenting on your attitude problem.

Fire away,
Buster.


Well look, I agree that I was the one doing the firing from the start. And
I don't want to start a fight over this, I would just like to see this
newsgroup a little bit more mechanic. Simple question = simple answer ||
simple redirection. I'm not faulting you for pointing me to a non-existent
FAQ, but if you take the one actually interesting comment that I made
throughout this thread, which is that the netiquette provided on the FAQ
page about "Please don't give them the location
of the appropriate FAQ," then this whole situation would have been avoided.
You would have went to try to find where it is, and if it was there,
depending on your mood you would have either given me the direct answer or
just pointed me to the section (which is ALRIGHT, it's fine to make people
dig a little), and in this case it wasn't there, so you probably would have
just replied with the answer as I'm sure that you knew it.

Anyway, let's just follow Rob Williscroft <rt*@freenet.RE MOVE.co.uk>'s
example and be very mechanical about this (he gave the first answer of this
I think without any comments or asides). If I had posted "What is
inheritance?", okay bust on me for noise, but even though the question I
posted was quite simple (I actually realized the answer once I saw it, but
I've been out of C++ for a while, hence the couple of posts today for the
first time in a while), it would have been just as simple to reply with the
answer, that's the only point I'd like to make.

Thank you,
Kevin Grigorenko
Jul 19 '05 #17
Kevin Grigorenko wrote in news:bk******** **@f04n12.cac.p su.edu:
Thanks. Following the loop, how would I know if there was an error or
if the loop exitted simply because of completion? Would checking
infile.eof() tell me whether it got to the end or not, and if
infile.eof() is false, can I assume there was some kind of stream
error?


Yes IIUC the eof() flag is set when you try to read at the EOF,
so if some other error occurs first eof() shouldn't be set.

Some more info here on stream states:

http://www.dinkumware.com/manuals/reader.aspx?b=p/
&h=ios.html#ios _base::iostate

or http://tinyurl.com/na3o

You'll hit a redirect first just click on the logo to get to the
real page.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #18
Kevin Grigorenko wrote:
std::string line;
std::ifstream infile("whateve r.txt", std::ios_base:: in);
while(!infile.e of())
{
infile >> line;
std::cout << line << std::endl;
line = "";
}
infile.close();


I see you got a lot of flame for this. I'll try an answer.

Use getline(infile, line) instead of infile >> line. See 20.3.15 in
Stroustrup's C++.

Christian

Jul 19 '05 #19

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

Similar topics

16
2305
by: qwweeeit | last post by:
In analysing a very big application (pysol) made of almost 100 sources, I had the need to remove comments. Removing the comments which take all the line is straightforward... Instead for the embedded comments I used the tokenize module. To my surprise the analysed output is different from the input (the last tuple element should exactly replicate the input line) The error comes out in correspondance of a triple string.
9
3658
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour. Could someone point me to the appropriate section, or else confirm the behaviour as a bug? For a particular project, I am using the C preprocessor phase only. I am not using the standalone program 'cpp' because proper functioning of my project...
1
1327
by: yeutim | last post by:
I can't find anything wrong this with this class. Especially, Overloading Stream-Extraction Operator (in blue). Any one know what do I need to fix this problem please reply. Thank you for your help! --------------------------------------------- class MyData{
0
1233
by: marfi95 | last post by:
I have an xml file that I want to maintain the whitespace on and spacing between my sections. I have something like this. <!-- Comment lines A --> <!-- Comment lines A --> <A> <B>test</B> <B>test1</B> <B>test2</B> </A>
1
2169
by: KevinGPO | last post by:
I am wondering about what's the best and easiest way to strip trailing whitespace from every single file in a folder, recursively. I want to write a program/script so that you pass in a folder name and it'll recursively go through all sub-folders and strips trailing whitespace from every single file. Trailing whitespace includes: 1. whitespaces at end of text lines, strip whitespace but retain text
1
2693
by: David | last post by:
I have rows of 8 numerical values in a text file that I have to parse. Each value must occupy 10 spaces and can be either a decimal or an integer. // these are valid - each fit in a 10 character block 123.8 123.8 1234.567 12345 12345 1234.567
16
4352
by: EM.Bateman | last post by:
Working on Visual Studio .Net I've implemented a class: #ifndef CONTRIBUTOR_H #define CONTRIBUTOR_H enum Gender {male=1, female, unk}; #include <iostream> #include <iomanip> #include <string>
6
2648
by: kaens | last post by:
Hey everyone, this may be a stupid question, but I noticed the following and as I'm pretty new to using xml and python, I was wondering if I could get an explanation. Let's say I write a simple xml parser, for an xml file that just loads the content of each tag into a dict (the xml file doesn't have multiple hierarchies in it, it's flat other than the parent node) so we have <parent>
5
2131
by: Taras_96 | last post by:
Hi all, Jesse Liberty writes: "cin.get() >>myVarOne >myVarTwo; // illegal The return value of (cin.get() >myVarOne) is an integer, not an iostream object." (http://newdata.box.sk/bx/c/htm/ch16.htm)
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.