How to make Cout (screen) buffer bigger?

Thanks anyone who help me with this :D in advance.

As I said in my description, the program generates TwinPrimes, from an initial range to a final range. The first output gets clear out, and the remaining one its the ones showing on the screen.

Example: initial Number 3
final Number 10000

At pair generation ( 6551 , 6553 ) When pairs get to 6500 and up. (If I'm not mistaken)

( 3 , 5 ) <=== This one already disappears on the screen , meaning that the screen only can hold 300 lines at same time. And repetitive will be clearing the screen and adding remaining pairs until the iteration gets at 10,000. (does the same with final number 6500 and up)

( 5 , 7 )

( 11 , 13 )

( 17 , 19 )

( 29 , 31 )

( 41 , 43 )

( 59 , 61 )

( 71 , 73 )

( ... , ... ) <==== Simulates the the whole generation of twin primes in between, just to demonstrate my point, and not take too much space on this post.

( 6359 , 6361 )

( 6449 , 6451 )

( 6551 , 6553 )


What to do, so the screen can get more than 300 lines at same time, without clearing out the first outputs of twin primes on the screen?

for the ease of the helper, I'll be posting the function definition that generates this outputs (twin primes) and prints them on the screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Verifica cuales son los pares de primos gémelos en el rango dado y los imprime.
void imprimePrimosGemelos(long &numero1, long &numero2, ofstream& salida)
{
	long j = numero1 + 2;
	long gemelos = 0;
	Primos unPrimo;

	for(long i = numero1; i < numero2; j = i + 2)
	{
		if(unPrimo.primo(j) == true)
		{

			cout <<  "\n\n\t ( " << i << " , " << j << " )";

			salida <<  "\n\n\t ( " << i << " , " << j << " )";

			gemelos++;
		}

		else 
		{

			while (unPrimo.primo(j) == false)
			{
				j+=2;
			}
			
		}

		i = j;

	}

	cout <<  "\n\n\t Total de nu'meros primos gemelos: " << gemelos 
		 << "\n\n\n\t";

	salida <<  "\n\n\t Total de nu'meros primos gemelos: " << gemelos;

	system("pause");
	system("cls");

}


Sorry if in on Spanish, since I'm from Latin America, my programs are mostly on my native language to the ease of the context for me.

Well any clues?

Thank you very much! Any help would be accepted

PSPMAN90
Last edited on
Wouldn't it be easier to send the output to a file? What you're trying to do is somewhat of a misuse of the console.
Well I actually output the results to a file, but our program must output to screen too.

So you know a way to resolve this or there's no way it's possible and I shouldn't do the output to screen?

Thank you for the fast response :)

PSPMAN90

You should just worry about sending output to the console. If the user needs a bigger buffer, that's his problem.
I don't think it is possible to make the windows console larger than 300 lines.

You could create a deque or list of twin primes instead of immediately printing them to cout and salida (which, BTW, you shouldn't do -- pick one output stream).

After running the "print twin primes" function, you can pass your list to another function which displays them in columns.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <list>
#include <iterator>  // para 'advance'
#include <utility>   // para 'pair'
using namespace std;

typedef unsigned long primo_t;

void generaPrimosGemelos(
  primo_t                          primero,
  primo_t                          ultimo,
  list <pair <primo_t, primo_t> > & lista )
{
  ...
  lista.push_back( make_pair( i, j ) );
  ...
}

void imprimePrimosGemelos( ostream& salida, const list <pair <primo_t, primo_t> > & lista )
{
  unsigned numero_de_lineas = (lista.size() + 3) / 4;

  lista <pair <primo_t, primo_t> > ::const_iterator iter[ 4 ];

  iter[0] = lista.begin();
  iter[1] = iter[0]; advance( c1, numero_de_lineas );
  iter[2] = iter[1]; advance( c2, numero_de_lineas );
  iter[3] = iter[2]; advance( c3, numero_de_lineas );

  for (unsigned n = 0; n < numero_de_lineas; ++n)
    {
    for (int n = 0; n < 4; n++)
      if (iter[ n ] != lista.end())
        {
        salida << " ( " << setw( 5 ) << right << iter[n]->first
               << " , " << setw( 5 ) << right << iter[n]->second
               << " ) ";
        }
    salida << endl;
    }
}

That will give you four columns (see line 20) of twin primes, each occupying 19 characters of space. It is OK if the length of your list of twin primes is not a multiple of four.

I have not verified this code -- it may have errors.

Hope this helps.
Woah , you are brilliant! But I haven´t take iterators and barely understand your code -_-... Sorry.
If I use your way, probably teacher would subtract points because he haven´t teach that yet, even if I knew it, I could be taking advantage over other students on the course...

But I can still use enums, arrays, template.

Remember I have to keep it simple... Perhaps I try to make the columns in a more simple way if there is...

Thanks, this will work for future reference :)

*oops* I didn't realize this was homework...

You could just count the number of twin primes you print to the screen, and require the user to press a key after every 25 or so...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <limits>
...

unsigned cnta = 0;
...
  cout << "cosas\n";
  if (++cnta >= 24)
    {
    cout << "Apreta INTRO para continuar..." << flush;
    cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
    cnta = 0;
    }

  salida << "cosas\n";

This has no effect on the output to the file (except that it happens at the same time as the output to the screen.)

Hope this helps.
Thanks for all your help :D
Glad to have you guys, Computer Science Gurus here. n_n¨!
Topic archived. No new replies allowed.