title: Using File Descriptors in Visual Studio 2010 and Windows
body: <p>I have a program in C++ which accepts some text from the user and saves it to a text file.  Here are snippets of the program:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;ctime&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;time.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;Windows.h&gt;
  
  using namespace std;
  
  int file_descriptor;
  size_t nob;
  
  int check_file(const char* full_path) //Method to check whether a file already exists
  {
      file_descriptor = open(full_path, O_CREAT | O_RDWR, 0777); //Checking whether the file exists and saving its properties into a file descriptor
  }
  
  void write_to_file(const char* text) //Method to create a file and write the text to it
  {
      time_t current = time(0); //Getting the current date and time
      char *datetime = ctime(&amp;current); //Converting the date and time to string
  
      nob = write(file_descriptor, "----Session----\n\n"); //Writing text to the file through file descriptors
      nob = write(file_descriptor, "Date/Time: %s\n\n", datetime); //Writing text to the file through file descriptors
      nob = write(file_descriptor, "Text: %s", text); //Writing text to the file through file descriptors
      nob = write(file_descriptor, "\n\n\n\n"); //Writing text to the file through file descriptors
  }
  </code></pre>
  
  <p>There are three main problems with this program:</p>
  
  <ol>
  <li><p>Visual Studio is telling me that it cannot open source file <code>&lt;unistd.h&gt;</code> (no such file or directory).</p></li>
  <li><p>Identifier <code>open</code> is undefined.</p></li>
  <li><p>Identifier <code>write</code> is undefined.</p></li>
  </ol>
  
  <p>How can I solve these problems please?  I am using Visual Studio 2010 on a Windows 7 platform.  I would like to make use of file descriptors in my program.</p>