two small questions,please answer!

hi, i have a trouble finding a way to clear the screen or open a new page like what we do in c . i thought may be i can use clrscr function ,but it seems that it doesn`t work in c++, i searched my books and find nothing.
and my next Q is that when i write : cin >> a , (a is int) then if i enter charachter ,it counts it as true=1 , how can i aviod this implicit conversion??
thanx in advance
like what we do in c

Such a function doesn't exist in C and never did. I think the borland compiler had such a function, but it's not part of the standard. There is no inbuilt functionality to clear the screen, because the way C++ is designed doesn't require the target platform to even have a screen that could be cleared in the first place. There are third party libraries like ncurses that provide such functions though.

cin >> a , (a is int) then if i enter charachter ,it counts it as true=1 , how can i aviod this implicit conversion??


Actually, this should just set cin into fail state, and it would probably not write any value to a at all (I am not sure, either the value of a is undefined or a remains the same, though you should probably just consider it's value undefined). cin>>(int) will attempt to convert the next string entered into an integer - a is not a string that can be converted to an integer, so the operation fails.
Last edited on
q1. yeah i used torbo c
q2:
may be this code can help :
in current function :
int a;
cin >> a;
if(a>=1 && a<5)
cout << "right";
**************
when i run and enter for example (g) it will go to if , think it as true and print "right", and when i chage a>=1 to a>1 the problem is gone
Last edited on
Declare a as a character, like
char a;
cin >> a;
It reads 1 as a = '1'.
If you want to do some math, then convert it to an integer latter.
Topic archived. No new replies allowed.