exception scanf()


I'm using the instruction below, but occurred exeception!

unsigned short ret = 0;
scanf("%d", &ret);

What Can I do?

The problem is caused by the non type safeness of scanf(). You pass the address of a unsigned short, but it expects an int. Since sizeof(int) > sizeof(unsigned short), scanf will try to access memory, it doesn't own.

For formatted input, use std::istream and it's realitves. You can read about them in the tutorial on this site.
What Can I do?

Use std::cin
Topic archived. No new replies allowed.