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<iostream>
#include<fstream>
#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(in, line)&&line!="")
//do something
in.close();
}
well just look at read..
thanks 3 26313
"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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<iostream> #include<fstream> #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(in, 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: "puzzlecracker" <ir*********@gmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.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<iostream> #include<fstream> #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(in, 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
"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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<iostream> #include<fstream> #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(in, 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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |