a simple question

ok lets say i have this

cout << 0;
cin.get();

ok lets say i have it in an endless loop

so whenever i press enter it will display 1 zero per line right?

but my question is how can i get it so if i press enter the next
zero will be on the same line right after the other one >.>?

so instead of looking like this:

0
0
0

it would look like this:

000

any help would be nice >.<
Since you have no endl; at the end of your cout statement I think it would print it out horizontally
to begin with. If not you could always just display 20 0s at once.
Thanks to Duoas for the gotoxy function:

(Windows solution)

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
#include <iostream>
#include <windows.h>

void gotoxy( int column, int line )
{
     COORD coord;
     coord.X = column;
     coord.Y = line;

     SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}

int main()
{
     unsigned long long numZeroes = 0;

     while(true)
     {
          std::cout << 0;
          std::cin.get();

          gotoxy( ++numZeroes, 0 );
     }

     return 0;
}
Last edited on
As far as I know there is no easy linux fix---ncurses or something and some programming effort are necessary here. Once u hit return you're on a new line...thats the thing about return isn't it?
This solution handles overflow correctly (though I just realized that after a line in the console has been filled, it reverts to printing zeroes vertically. Will have to add a check to see if a line has been filled, and if so, increment the line).

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 <iostream>
#include <windows.h>

void gotoxy( int column, int line )
{
     COORD coord;
     coord.X = column;
     coord.Y = line;

     SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}

int main()
{
     int numZeroes = 0;
     int line = 0;

     while(true)
     {
          std::cout << 0;
          std::cin.get();

          if(++numZeroes < 0)
          {
               //overflow
               numZeroes = 0;
               line++;

               if(line < 0)
               {
                    //overflow
                    break;
               }
          }

          gotoxy( numZeroes, line );
     }

     return 0;
}
Topic archived. No new replies allowed.