conio.h

hello guys,
Mine is a simple doubt what is the best alternative for clrscr() and getch().some says the header file for this functions conio.h is not a standard header file and these are differently explained.I tried using system("cls") but it is also said to be evil.
1
2
clrscr //to clear the screen
 getch() //for pausing the screen as user can view the result  

edit::correct me if I am wrong
Unless you wanted to use the console for a wrong purpose, there is no need to clear the screen. But if you had a bad professor that made you do it, this is how you should do it:
http://www.cplusplus.com/articles/4z18T05o/

As for pausing and waiting for the user to acknowledge that they have read the information on screen, you would write a function like this:
1
2
3
4
void WaitForEnter()
{
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
And call it whenever you like.
1
2
3
4
5
int x;
std::cin >> x;
std::cout << "read me\n";
WaitForEnter();
std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

Won't it just skip already present newline symbol (Which stream exctraction operator will leave in)
That is programmer error - the programmer should always account for the extra newline after inputting values with the formatted extraction operator.
Unless you wanted to use the console for a wrong purpose, there is no need to clear the screen

hey guys i use clrscr()at the begining of the code to clear the screen so as to start afresh.It's sort of like to start things at a new page.But the waitforenter() function is nice and,so there is no alternative for clrscr()?
Last edited on
That is programmer error - the programmer should always account for the extra newline after inputting values with the formatted extraction operator.

More like a design error: you are forcing programmer to study implementation details of particular function:
What is it doing: Waiting until user presses enter.
How is it done: Function skips all symbols up to first encountered newline, so it will not work if there is already an unextracted newline symbol in input stream and programmer should account to that....

In opposite standard getline() function:
What: Stores characters from input stream in string until it encounters delimeter which is extracted, but not stored. Default delimeter is newline character.
How: I don't care.

You could either rename function into something like "readNewline()", fix this behavior or tell that it is "not a bug, it's feature" by documenting it. I think this is how some strange requirements are getting into normative documents in all fields around all the world...

cyberdude
Standard console doesn't clears screen after each program run. And there is good reasons for that. I you still want it, you were provided by L B with link to article with several alternative ways to do this. The simpliest is to just output a bunch of newlines.
Last edited on
thanks MiNiPaa and LB.got it thanks guys
Topic archived. No new replies allowed.