C++ code with conio.h

Hi,

I am new here and new to C++. I am using a book to learn C++. I had this code from the book which contains conio.h library. I know this is a window thing, I want to know how may I change this code to work on Linux. I use Linux only on my machine.
Here is the code:
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
// showprim.cpp
// displays prime number distribution
#include <iostream>
using namespace std;
#include <conio.h>               //for getche()

int main()
   {
   const unsigned char WHITE = 219;  //solid color (primes)
   const unsigned char GRAY  = 176;  //gray (non primes)
   unsigned char ch;
				       //for each screen position
   for(int count=0; count<80*25-1; count++)
      {
      ch = WHITE;                //assume it’s prime
      for(int j=2; j<count; j++) //divide by every integer from
      if(count%j == 0)           //2 on up; if remainder is 0,
	 {
	 ch = GRAY;                //it’s not prime
	 break;                    //break out of inner loop
	 }
      cout << ch;                //display the character
      }
   getch();                      //freeze screen until keypress
   return 0;
   }


I will be grateful if you can help me. It is this getche() thing which causes me a headache with some codes in this book.

faizlo
Since you aren't using cin anywhere in the code, you could just use cin.ignore(1). Otherwise, refer to: http://www.cplusplus.com/forum/beginner/1988/
Just remove line 5 and replace line 26 with
cin.get();
Last edited on
Topic archived. No new replies allowed.