C++: how to check my directory disk space

I have a directory, and I write some files in to that. How to throw the error exception when my directory is full. i.e. there is no disk space

Whether there's sufficient space left is normally not a concern of the directory but of the whole file system. There are things like quotas, which are normally supported by default by any distributor-made standard kernel but which have to be activated first.
So, I guess a call to statvfs() should do it.

From the man-page of write(2):