Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What else can i use bc F_OK is throwing an error sayinf identidier is undefined

ID: 3865732 • Letter: W

Question

What else can i use bc F_OK is throwing an error sayinf identidier is undefined and i cant figure it out. on visual studios 2017 windows com. already have io.h header, but unistd.h wont work says its for unix.? hope that question is phrased correctly

is there a different way to state that the file doesnt exist in the if statment or remove it all together so that it will still return false with a different staement

bool DoesUserExist(std::string username)
{
std::string user_file_name = GetUserFile(username);

if (access(user_file_name.c_str(), F_OK) != -1)
{
  return true;
}
else
{
  return false;
}
}

Explanation / Answer

F_OK is nothing but an integer variable const with a value of 0. If you don't want to use that, you can just define your own const with value 0 and use that.

as

const int MY_OK = 0;
Now use MY_OK instead of F_OK anywhere... You don't need to use unistd header file in this case.

Your function will become as:

const int MY_OK = 0;

bool DoesUserExist(std::string username)

{

std::string user_file_name = GetUserFile(username);

if (access(user_file_name.c_str(), MY_OK) != -1)

{

return true;

}

else

{

return false;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote