Writing/reading data structure to a file using C++
The trouble with writing binary blobs is that they lead to brittle storage.

The stored objects have a tendency to break over time as the assumptions you make about the hardware no longer hold true (in this case that the sizeof(int) is constant and the endianess of int will not change).

It has become more standard therefore to use a method know as serialization. In this you convert the object to a format that is hardware agnostic (and usually human readable).

Note: Binary blobs have advantages. But you must weigh those against the brittleness. Therefore your first choice should be serialization (unless you have specific requirements that prevents this). Then look at binary Blobs only after you have shown that serialization has too much overhead (unlikely for most situations, but it is a possibility).

In C++ you would do this using the operator&lt;&lt; and operator&gt;&gt;.

I would re-write your code as:

struct WebSites
{
    std::string siteName;
    int rank;

    WebSite()
        : siteName("")
        , rank(0)
    {}

    WebSite(std::string const&amp; siteName, int rank)
        : siteName(siteName)
        , rank(rank)
    {}
    void swap(WebSites&amp; other) throws()
    {
        std::swap(rank,     other.rank);
        std::swap(siteName, other.siteName);
    }
};
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, WebSites const&amp; data)
{
    stream &lt;&lt; data.rank &lt;&lt; " " 
           &lt;&lt; data.siteName.size() &lt;&lt; ":" 
           &lt;&lt; data.siteName;
    return stream;
}
std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, WebSites&amp; data)
{
    WebSite     tmp;
    std::size_t size;
    if (stream &gt;&gt; tmp.rank &gt;&gt; size)
    {
        tmp.siteName.resize(size);
        if (stream.read(tmp.siteName[0], size)
        {
            data.swap(tmp);
        }
    }
    return stream;
}


Now you can write your code like this:

int _tmain(int argc, _TCHAR* argv[])
{
    WebSite s1("www.ppp.com", 0);    
    WebSite s2("www.rrr.com", 111);
    WebSite s3("www.code.com", 123);
    WebSite s4("www.yahoo.com", 14);

    // write
    fstream binary_file("c:\\test.dat",ios::out|ios::binary|ios::app);
    binary_file &lt;&lt; s1 &lt;&lt; s2 &lt;&lt; s3 &lt;&lt; s4;
    binary_file.close();

    // Read data
    fstream binary_file2("c:\\test.dat",ios::binary|ios::in| ios::ate );
    WebSites p_Data;
    while(binary_file2 &gt;&gt; p_Data)
    { 
        cout &lt;&lt; p_Data.SiteName &lt;&lt; endl;
        cout &lt;&lt; "Rank: "&lt;&lt; p_Data.Rank &lt;&lt; endl;
    }
    binary_file2.close();

    // Read data into a vector
    fstream binary_file3("c:\\test.dat",ios::binary|ios::in| ios::ate );
    std::vector&lt;WebSites&gt; v;

    std::copy(std::istream_iterator&lt;WebSites&gt;(binary_file3),
              std::istream_iterator&lt;WebSites&gt;(),
              std::back_inserter(v)
             );
    binary_file3.close();
}