I got the solution
#include "stdafx.h"
#include <fstream>
#include <windows.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
while(true)
{
WIN32_FIND_DATA data;
HANDLE h = FindFirstFile(L"D:\\*.*",&data); \\ Specify the drive letter
if( h!=INVALID_HANDLE_VALUE )
{
cout << "Waiting\n";
}
else
cout << "Formatting\n";
FindClose(h);
Sleep(1000);
}
getchar();
return 0;
}