How can I make a scrolling text in c++?
If someone know some code that can read an external file and make it scroll on the program window, lease help me!!!
:confused:
Printable View
How can I make a scrolling text in c++?
If someone know some code that can read an external file and make it scroll on the program window, lease help me!!!
:confused:
>How can I make a scroll bar in c++?
With a windowing API.
>If someone know some code that can read an external file and make it scroll on the program window, lease help me!!!
Is this on a textual command line or a GUI based program?
A short question deserves a short answer.
Look here.
Since you did not specify what API, I assume you're using the Windows API.
For the reading I would use <iostream>. I don't know what kind of window "program window" is, but I would just use SetWindowText() on a multiline edit control.Quote:
read an external file and make it scroll on the program window
I was bored, so here's a way to scroll with a text interface:
"But Prelude, it only scrolls one line at a time!" Duh, of course it does, but adding the functionality for more than one line at a time is simple enough to be left as an exercise. :)Code:#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <conio.h>
using namespace std;
vector<string> map_file ( ifstream& in );
int main()
{
ifstream in ( "input.txt" );
if ( !in.is_open() )
return EXIT_FAILURE;
vector<string> file = map_file ( in );
vector<string>::size_type scroll = 0;
cout<<"How to scroll: Up = j, Down = k, Quit = q"<<endl;
for ( ; ; ) {
cout<< file[scroll] <<endl;
switch ( getch() ) {
case 'j':
if ( scroll > 0 )
scroll--;
break;
case 'k':
if ( scroll < file.size() - 1 )
scroll++;
break;
case 'q':
return EXIT_SUCCESS;
}
}
}
vector<string> map_file ( ifstream& in )
{
vector<string> file;
string line;
while ( getline ( in, line ) )
file.push_back ( line );
return file;
}
Interesting way of implementing scrolling, Prelude. :)
two questions about this.....
a) what does the last function do?
it returns a vector of strings and takes a reference to an ifstream object is all i know.
b) : vector<string>::size_type scroll = 0;
what is that? is size_type an enum or what?
>a) what does the last function do?
It reads the contents of a file, line by line, into a vector of strings. It's a convenience function so that you don't have to do it in main.
>what is that? is size_type an enum or what?
size_type is a type (usually a typedef) defined by std::vector to represent a value that holds a valid index. It is equivalent to size_t in function, except restricted to vectors.
so size_type is used to prevent overrun?
vector<string>::size_type scroll = 0;
and this is (im guessing here.....) a static member variable?