Alternative to system("Pause");

I spent about and hour reading past topics in the forum, and yes I know this is a sore point. So as a beginner, I would like to get it right from the start. I understand the dangers of using System() calls, so I'm trying to write an alternative to sysytem("pause"). This is the code I've written so far, but how compatible is it with other compilers or systems?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Tested OK on DevC++ 4.9.9.2, Borland C++ Builder 6.0 and MSVC++ 6.0

#include <conio.h>
#include <iostream>

using namespace std;

void pause()
{
     cout << "Press any key to continue....";
     while(1)
     {            
          if(kbhit())
          {
               break;
          }
     }
}     

int main()
{
     pause();
     return EXIT_SUCCESS;
}
char f;
cin >> f;

Works fine. Even if its ugly.
Otherwise i have no idea
I have been told so many times that kbhit() is "not standard C++" but I'm not sure what that matters as far as compatibility with most used architectures (linux,win,mac). The only thing I'd suggest is you call getch() before breaking out to clear the key that was hit out of the buffer.
I have been told so many times that kbhit() is "not standard C++"


A keyboard is not standard C++ :p
@Moschops
I have been told so many times that kbhit() is "not standard C++"


Thanks for clearing that up.
try using cin.ignore().
Here's a fair solution.
cin.get();
What about system("CLS");
Oops! Not the old system("CLS"); again LOL
Topic archived. No new replies allowed.