9 Replies - 1641 Views - Last Post: 30 December 2006 - 12:44 PM Rate Topic: -----

#1 mweimin86   User is offline

  • New D.I.C Head

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

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

Post icon  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   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • 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

View Postmweimin86, 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
Was This Post Helpful? 0
  • +
  • -

#3 mweimin86   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
}


Edit: Added code tags. ~Videege

Attached File(s)

  • Attached File  text.txt (5.3K)
    Number of downloads: 77

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

Was This Post Helpful? 0
  • +
  • -

#4 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • 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
}


Was This Post Helpful? 0
  • +
  • -

#5 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#6 mweimin86   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#7 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • 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();
}


Was This Post Helpful? 0
  • +
  • -

#8 mweimin86   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#9 mweimin86   User is offline

  • New D.I.C Head

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

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

Posted 30 December 2006 - 12:23 PM

View Posthorace, 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??
Was This Post Helpful? 0
  • +
  • -

#10 mweimin86   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1