# C++ can it program to display a long page sequentially?

Page 1 of 1

## 9 Replies - 1641 Views - Last Post: 30 December 2006 - 12:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=22472&amp;s=cd1929e9bfad2aa42fb2b1407f0e7d83&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mweimin86

Reputation: 0
• Posts: 6
• Joined: 30-December 06

# C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 06:05 AM

normally we use [cout] display data,

but now if doing it to display a [.txt] file page by page on the screen.
which is being input to the screen by the [fstream].
What command can be use to get this function.

using [if] [else] only can make it to a fix number of line to display,
how is it can display to sequentially to fix total widthness of the screen page.

it should be something like DOS when u type [dir/p]
which display all directory page by page.

thank you.

Is This A Good Question/Topic? 0

## Replies To: C++ can it program to display a long page sequentially?

### #2 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 08:31 AM

mweimin86, on 30 Dec, 2006 - 01:05 PM, said:

normally we use [cout] display data,

but now if doing it to display a [.txt] file page by page on the screen.
which is being input to the screen by the [fstream].
What command can be use to get this function.

using [if] [else] only can make it to a fix number of line to display,
how is it can display to sequentially to fix total widthness of the screen page.

it should be something like DOS when u type [dir/p]
which display all directory page by page.

thank you.

(1)have a counter which you zero at the start of each page.
(2) as you read each line from the file and display it increment the counter
(3) when the counter reaches your page length ask the user to hit the <Enter> key to continue
(4) call getchar();
back to (1) etc. until you reach the end of the file

### #3 mweimin86

Reputation: 0
• Posts: 6
• Joined: 30-December 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 10:40 AM

Thank you alot man....

but would you mind cause i think i may have alot more question to ask for help..

what i doing is a info inquiry system project it something like a search data infomation but displaying the database.

it need to be able to:

1.display info of text.txt info sequentially with the fuction of forward one record, backward one record, go to first record and go to last record.

2. able to search by the infor by number or name. (like first line number '1' of the text.txt is being change to 'Dream in code'.
how is it able to search for the whole line of the ' Dream in code' data line .

wish is :

Dream in code M 12 S1234 68000000 T1600

'1' been change to 'Dream in code'

when i display this, all content is display at one.
if i make a number of line to display each time, like 10 lines once,
it will be difference and not use if i maximize my screen.
is there a way that it can detact the number of line on screen to display page by page that will auto detact the amount of line can display on the current screen??

thank you....

//my_program.cpp
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void main()
{
string str;

fstream infile("d:\\text.txt");

cin.get();

for (int i=0; i<=4350; i= i+29)
{
getline(infile,str);
cout << str << endl;
}

infile.close;
}


#### Attached File(s)

•  text.txt (5.3K)

This post has been edited by Videege: 30 December 2006 - 11:43 AM

### #4 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 11:32 AM

initially the display page by page could be something like
int counter=0;
for (int i=0; i<=4350; i= i+29)
{
getline(infile,str);
cout << str << endl;
if(counter++ > 10)
{ cin.get(); counter=0; }  // after a page wait
}



### #5 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 11:57 AM

looking at your data file which contains records like
1	M	12	S1234	68000000	T1600
2	F	12	S1235	68000001	T1601
3	M	12	S1236	68000002	T1602



it would probably be a good idea to create a structure or a class to hold a record then store the records in a vector or similar data structure. It would then be (fairly) simple to more up and down the data structure displaying records and seraching.

This post has been edited by horace: 30 December 2006 - 11:58 AM

### #6 mweimin86

Reputation: 0
• Posts: 6
• Joined: 30-December 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 11:59 AM

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void main()
{
string str;

fstream infile("d:\\text.txt");

cin.get();
int counter=0;

for (int i=0; i<=4350; i= i+29)
{
getline(infile,str);
cout << str << endl;

if(counter++ > 10)
{ cin >> i; counter=0; }  // after a page wait
infile.close;
}}



i change the [cin.get();] to [cin >> i;] it should change my for loop i back to the number i enter. how come i cannot do so and the program take it as not effect???

EDIT: Added more code tags ~Dark_Nexus

### #7 horace

• D.I.C Lover

Reputation: 768
• Posts: 3,832
• Joined: 25-October 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 12:03 PM

think you have a } in the wrong place - here is the whole program
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
string str;
fstream infile("d:\\text.txt");

int counter=0;
for (int i=0; i<=4350; i= i+29)
{
getline(infile,str);
cout << str << endl;
if(counter++ > 10)
{ cin.get(); counter=0; }  // after a page wait
}

infile.close();
cin.get();
}



### #8 mweimin86

Reputation: 0
• Posts: 6
• Joined: 30-December 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 12:15 PM

thanks, i been using the class for my program

but my program is about displaying my data using the <fstream>

how could i able to store the data into my program array.

and display data of each person to be able to forward and backward one record.

[/quote]

Name: Gender Age ID Tel Room

John M 12 S1234 68000000 T1600
Mary F 12 S1235 68000001 T1601

This post has been edited by mweimin86: 30 December 2006 - 12:18 PM

### #9 mweimin86

Reputation: 0
• Posts: 6
• Joined: 30-December 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 12:23 PM

horace, on 30 Dec, 2006 - 12:03 PM, said:

think you have a } in the wrong place - here is the whole program
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
string str;
fstream infile("d:\\text.txt");

int counter=0;
for (int i=0; i<=4350; i= i+29)
{
getline(infile,str);
cout << str << endl;
if(counter++ > 10)
{ cin.get(); counter=0; }  // after a page wait
}

infile.close();
cin.get();
}



This display my data first 10 then the next 10.

how can i make it to display back to the last 10

e.g

no. 30-40 is being display,

now i with to enter a key for it to be able to go back to display the no 1-10 again.

is it able to do so??

### #10 mweimin86

Reputation: 0
• Posts: 6
• Joined: 30-December 06

## Re: C++ can it program to display a long page sequentially?

Posted 30 December 2006 - 12:44 PM

anyway thank you alot ...

#include <fstream>

how is it able to write in data like name to a namearray[]

and display the database to be able to display forward one back or backward one page by the selection of the user???

A big Thanks for your reply and a great happy new yr