I want to read lines and skip blank lines:
would this work considering the lines can contain tabs, spaces, etc.?
file.in:
------
line1
line2
line3
...
#include<iostre am>
#include<fstrea m>
#include<string >
using namespace std;
int main(int argc, char *argv ){
read(argv[1]);
}
void read(char * filename){
infile in(filename);
string line;
while(getline(i n, line)&&line!="" )
//do something
in.close();
}
well just look at read..
thanks 3 26380
"puzzlecrac ker" <ir*********@gm ail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I want to read lines and skip blank lines:
would this work considering the lines can contain tabs, spaces, etc.?
file.in: ------ line1
line2
line3 ..
#include<iostre am> #include<fstrea m> #include<string >
using namespace std;
int main(int argc, char *argv ){
read(argv[1]); }
void read(char * filename){
infile in(filename); string line; while(getline(i n, line)&&line!="" ) //do something
in.close();
}
well just look at read..
thanks
Your code doesnt' skip blank lines, just empty lines. You need something
like this
to scan the entire line to see that there's some non-whitespace..
if ( line.find_first _not_of(" \t\v\r\n") )
{
}
Dave Townsend wrote: "puzzlecrac ker" <ir*********@gm ail.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I want to read lines and skip blank lines:
would this work considering the lines can contain tabs, spaces, etc.?
file.in: ------ line1
line2
line3 ..
#include<iostre am> #include<fstrea m> #include<string >
using namespace std;
int main(int argc, char *argv ){
read(argv[1]); }
void read(char * filename){
infile in(filename); string line; while(getline(i n, line)&&line!="" ) //do something
in.close();
}
well just look at read..
thanks
Your code doesnt' skip blank lines, just empty lines.
[snip]
It does not skip empty lines either. It simply stops when it sees the first
blank line or the end of the file.
Best
Kai-Uwe Bux
"puzzlecrac ker" <ir*********@gm ail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I want to read lines and skip blank lines:
would this work considering the lines can contain tabs, spaces, etc.?
file.in: ------ line1
line2
line3 ..
#include<iostre am> #include<fstrea m> #include<string >
using namespace std;
int main(int argc, char *argv ){
read(argv[1]); }
void read(char * filename){
infile in(filename); string line; while(getline(i n, line)&&line!="" ) //do something
First, I think you want:
while ( getline( in, line ) )
if ( line != "" )
// do something
so it'll continue to read even if it sees an empty line.
Read the other response, becuase if the line has a single space, it won't
work. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ruben |
last post by:
Hello.
I am trying to read a small text file using the readline statement. I
can only read the first 2 records from the file. It stops at the blank
lines or at lines with only spaces. I have a while statement checking
for an empty string "" which I understand represents an EOF in Python.
The text file has some blank lines with spaces and other with blanks.
Thanks a lot.
|
by: Tappy Tibbons |
last post by:
I have a class I am serializing, and need the resultant XML to skip/omit
classes that are not initialized, or their member variables have not been
set. Is this possible?
Say for the following code, sometimes the Person may not have given us one,
both, or either of their addresses.
The serialize function will still put in a "<BillingAddress />" tag
indicating no data. I want it to completely omit the tag if the class is
empty, similar...
|
by: Melissa |
last post by:
Does anyone have a generic procedure for adding blank lines to reports like
Sales details, PO details and/or Orders details. The procedure would need to
count the number of line items, determine the remaining page to fill and
print blank lines with the same number of fields as the line items. In
addition, if there were a long list of line items that carried over to a
second and possibly more pages, to print blank lines at the last page. The...
|
by: FrancisC |
last post by:
How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7
i.e., I want to get the "7" in the third line, how can I do that?
thx!!
|
by: Just Me |
last post by:
In the handler QueryPageSettings I let the user select a "Skip This Page"
option.
But I don't know how to handle it if he does.
I can set a flag and in PrintPage skip printing the page but the page count
in Printer and Faxes still increments.
I can cancel the entire print job but can not find anything that will enable
me to skip one page.
| |
by: Jeff Calico |
last post by:
Hello everyone
I am transforming an XML document to text, basically only outputting
a small portion of it. When I run the following XSLT via Xalan's
processor,
I get a bunch of unwanted blank lines in the output.
Here is a simplified XML and XSLT:
(Note the problem does not happen when testing in XMLSpy)
- - - - - - - - - - - - - - - - - - - - - - - -
|
by: John |
last post by:
I need to read data from the file like the following with name and
score, but some line may only has name without score:
joe 100
amy 80
may
Here's my code, but it couldn't read the line with "may" because there
is no score. Anyone knows what is the workaround to this problem?
|
by: jatindersingh80 |
last post by:
Hi ,
i am reading a text file with token # but somtimes blank lines comes between the line at blank line the code gives exception of no such element the text files contains data after blank lines
jatinder
|
by: luckyyyyyy |
last post by:
I appriate your work but...
guys i have another problm.....i wana skip first 9 lines from my data file and after skipping i wana read x,y,z at the end of file. i did but after while loop is end it again skip these 9 lines. how to solve this.
and also i wana distinguish these float data and unsigned data, as you can see in data file. after 9 lines, 6 lines are the float data, after this 6 lines are unsigned int.
actually this file has a...
|
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...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |