473,385 Members | 1,676 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,385 software developers and data experts.

searching to a specific line in file

Hello all!!

Is there an algorithm out there that will allow you to go to a
specific line in a .txt...and start outputing to the screen at that
line until end of record

Here is a code that i implemented...
while(istrm1.peek() != EOF)
{

++count;
if(count==RBNx)
{

for(int i = 0 ; i < endofRec; i++)
{
istrm1.getline(line,512);
cout<<line<<endl;
}
istrm1.seekg(ios::clear,ios::begin);
istrm1.clear();
break;
}
istrm1.ignore(128, '\n');

}

Apr 9 '07 #1
2 1859
uche wrote:
Is there an algorithm out there that will allow you to go to a
specific line in a .txt...and start outputing to the screen at that
line until end of record

Here is a code that i implemented...
while(istrm1.peek() != EOF)
{

++count;
if(count==RBNx)
{

for(int i = 0 ; i < endofRec; i++)
{
istrm1.getline(line,512);
I think if you use 'std::getline' instead of 'std::stream::getline',
you'd be able to take advantage of 'std::string's ability to grow
and will not be limited by 512 characters.
cout<<line<<endl;
}
istrm1.seekg(ios::clear,ios::begin);
istrm1.clear();
break;
}
istrm1.ignore(128, '\n');
You're only ignoring 128 chars at a time. What if a line is longer?
You'd count it as two lines, right?
>
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 9 '07 #2
uche skrev:
Hello all!!

Is there an algorithm out there that will allow you to go to a
specific line in a .txt...and start outputing to the screen at that
line until end of record
End of file?
>
Here is a code that i implemented...
while(istrm1.peek() != EOF)
{

++count;
if(count==RBNx)
What is 'RBNx'?
{

for(int i = 0 ; i < endofRec; i++)
{
istrm1.getline(line,512);
cout<<line<<endl;
}
istrm1.seekg(ios::clear,ios::begin);
istrm1.clear();
break;
}
istrm1.ignore(128, '\n');

}
Your posted code is rather incomplete.

#include <fstream>
#include <string>
#include <ostream>
#include <algorithm>

void fskip(std::istream & in, unsigned nolines) {
std::string rbuf;
while(nolines-- && std::getline(in,rbuf).good());
}

void fout(std::istream & in) {
std::copy(std::istream_iterator<char>(in),
std::istream_iterator<char>(),
std::ostream_iterator<char>(std::cout));
}

int main(int argc, char* argv[])
{
std::ifstream in("text");
fskip(in,3);
fout(in);
return 0;
}
Apr 9 '07 #3

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

Similar topics

1
by: Rajarshi Guha | last post by:
Hi, I have a large list of words (each on its own line) and I would like to find words that contain a specific string. I have been trying to use a regexp but I cant see how I can find the word...
14
by: Ludwig77 | last post by:
I read that there are some tags that can be entered in a web page's meta tags in order to prevent web bot searching and indexing of the web page for search engines. What is the tagging that I...
2
by: Mark Reed | last post by:
Hi all, I don't know if this is do-able but you never know until you ask. A situation at work has arisen where I have to trawl through over 500 text files, copy the contents and then paste them...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
2
by: angus | last post by:
hello everybody, i'm having some problems searching a text file and then deleting the line. since i used fileopen(), i can use the eof() function to loop through the file, searching for the...
0
by: CAIBird | last post by:
hi, My web app ran into a error when decrypt section"system.net/mailSettings/smtp", following is the details: ...
3
by: radicaled | last post by:
Hi, I'm trying to make a program for the school, but I'm having some trouble with the fseek function. Well, I have a txt file with words with different lengths, so when I try to open an specific...
3
by: Ahmad Jalil Qarshi | last post by:
Hi, I have a text file having size about 2 GB. The text file format is like: Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values For example...
3
by: Gene Kelley | last post by:
Hello PHPers, I'm trying to get at a single line within a text file. For instance, I want to print the line within a the file named "file.txt" that starts with "17:". file.txt contains...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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 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.