Loading and comparing files containing 3D data I have written a program to compare two 3D raw data equal or different. But I think the time consuming would be reduced if I use the STL. How to improve the program? The complete and varifiable code is showed as follows:

#include &lt;cstdio&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;assert.h&gt;
#include &lt;cstdlib&gt;

using namespace std;

int LoadSample(std::string path_sample, unsigned char*&amp; raw_data, int* w_h_d) {

    FILE *fp;
    if (  fopen_s(&amp;fp, path_sample.c_str(),"rb") ) 
        return 1; 

    int width = 0;
    int height = 0;
    int depth = 0;

    fread(&amp;width,4,1,fp);
    fread(&amp;height,4,1,fp);
    fread(&amp;depth,4,1,fp);

    w_h_d[0] = width;
    w_h_d[1] = height;
    w_h_d[2] = depth;

    raw_data = (unsigned char*)malloc(width*height*depth*sizeof(unsigned char));
    fread(raw_data,height*width*depth,1,fp);
    fclose(fp);

    return 0;
}

int CompareData(unsigned char*&amp; data_train, int* train_w_h_d, unsigned char*&amp; data_test, int* test_w_h_d) {

    if (train_w_h_d[0] == test_w_h_d[0] &amp;&amp; train_w_h_d[1] == test_w_h_d[1] &amp;&amp; train_w_h_d[2] == test_w_h_d[2]) {

        std::cout&lt;&lt; "Size is equal!\n";

        int all_num = train_w_h_d[0]*train_w_h_d[1]*train_w_h_d[2];
        int count = 0;
        for(int i = 0; i &lt; all_num; i++) {
            if(data_train[i] == data_test[i])
                count++;
        }

        if(all_num == count)
            return 1;

    }
    return 0;
}

int main(){

    string root_path = "F:\\SZU\\Projects\\Fetal_Face\\data\\";
    string filepath_train = root_path + "train\\";
    string filepath_test = root_path + "test\\detect_data\\";

    unsigned char* data_train = NULL;
    unsigned char* data_test = NULL;

    int num_train = 127;
    int num_test = 80;
    int train_w_h_d[3] = {0, 0, 0};
    int test_w_h_d[3] = {0, 0, 0};
    for (int i = 0; i &lt; num_train; i++) 
        for (int j = 1; j &lt;= num_test; j++) {

            char num_i[10], num_j[10];
            _itoa_s(i, num_i, 10);
            _itoa_s(j, num_j, 10);
            std::string file_train = filepath_train + "data_" + num_i + ".raw";
            std::string file_test = filepath_test + "data_" + num_j + ".raw";

            if( LoadSample(file_train, data_train, train_w_h_d) )
                std::cout&lt;&lt; "Error: load train data.\n";

            if ( LoadSample(file_test, data_test, test_w_h_d) ) 
                std::cout&lt;&lt; "Error: load test data.\n";

            if( CompareData(data_train, train_w_h_d, data_test, test_w_h_d) ) {
                std::cout&lt;&lt; "Same data: " &lt;&lt; i &lt;&lt; "-- train\t\t" &lt;&lt; j &lt;&lt; " -- test\n"&lt;&lt;std::endl;
                system("PAUSE");
            }
            else{
                std::cout&lt;&lt; i &lt;&lt; "-- train\t\t" &lt;&lt; j &lt;&lt; " -- test is difference." &lt;&lt;std::endl;
            }


            delete[] data_train;
            data_train = NULL;
            delete[] data_test;
            data_test = NULL;
    }

    return 0;
}


The code can run correctly but I want to improve the efficiency by the STL. My compiler is VS2008.

So, how to revise it? By the way, what and where is potential error or something be able to develop in my code.
For inequality, it is sufficient to have one difference. If one difference is found, it's unnecessary to compare more data. There's no point in counting equal data entries and compare that number to the total number of entries, because a single inequality will reduce that number making it impossible to be the same as the total number of entries.

if(data_train[i] == data_test[i])
            count++;


Should be

if(data_train[i] != data_test[i])
            return 0;