Stdafx h no such file or directory ошибка

I am new to visual studio.I have created a simple console application and then selected an empty project of c++.Then pasted the following code

#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <fstream>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <vector>
#include "GL/glut.h"      
#include "GL/glu.h"    
#include "GL/gl.h"   
#include <math.h>
#include <time.h>

using namespace std;
using namespace cv;

const float zNear = 0.05;
const float zFar = 500.0;
int width, height;
int draw = 0;
Point FIX_X(0, 0), FIX_Y(0, 0), FIX_Z(0, 0);
float skew_x, skew_y, skew_z;
VideoCapture cap(0);
Mat tmp, test;
Mat intrinsic_Matrix(3, 3, CV_64F);
Mat distortion_coeffs(8, 1, CV_64F);
Mat Projection(4, 4, CV_64FC1);
double largest_area;
int largest_contour_index;
int n = 0;
int no_of_fingers = 0;
vector<vector<pair<float, Point>>> position;
vector<int> finger_count;
Point first, second, third;
float size_of_pot = 10;
int rot_angle = 10;

float distanceP2P(Point a, Point b) {
    float d = sqrt(fabs(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)));
    return d;
}
float getAngle(Point s, Point f, Point e) {
    float l1 = distanceP2P(f, s);
    float l2 = distanceP2P(f, e);
    float dot = (s.x - f.x)*(e.x - f.x) + (s.y - f.y)*(e.y - f.y);
    float angle = acos(dot / (l1*l2));
    angle = angle * 180 / 3.147;
    return angle;
}


String intToString(int number) {
    stringstream ss;
    ss << number;
    string str = ss.str();
    return str;
}

bool pairCompare(const pair<float, Point>&i, const pair<float, Point>&j) {
    return i.first <j.first;

}

GLfloat* convertMatrixType(const cv::Mat& m)
{
    typedef double precision;

    Size s = m.size();
    GLfloat* mGL = new GLfloat[s.width*s.height];

    for (int ix = 0; ix < s.width; ix++)
    {
        for (int iy = 0; iy < s.height; iy++)
        {
            mGL[ix*s.height + iy] = m.at<precision>(iy, ix);
        }
    }

    return mGL;
}

void generateProjectionModelview(const cv::Mat& calibration, const cv::Mat& rotation, const cv::Mat& translation, cv::Mat& projection, cv::Mat& modelview)
{
    typedef double precision;

    projection.at<precision>(0, 0) = 2 * calibration.at<precision>(0, 0) / width;
    projection.at<precision>(1, 0) = 0;
    projection.at<precision>(2, 0) = 0;
    projection.at<precision>(3, 0) = 0;

    projection.at<precision>(0, 1) = 0;
    projection.at<precision>(1, 1) = 2 * calibration.at<precision>(1, 1) / height;
    projection.at<precision>(2, 1) = 0;
    projection.at<precision>(3, 1) = 0;

    projection.at<precision>(0, 2) = 1 - 2 * calibration.at<precision>(0, 2) / width;
    projection.at<precision>(1, 2) = -1 + (2 * calibration.at<precision>(1, 2) + 2) / height;
    projection.at<precision>(2, 2) = (zNear + zFar) / (zNear - zFar);
    projection.at<precision>(3, 2) = -1;

    projection.at<precision>(0, 3) = 0;
    projection.at<precision>(1, 3) = 0;
    projection.at<precision>(2, 3) = 2 * zNear*zFar / (zNear - zFar);
    projection.at<precision>(3, 3) = 0;


    modelview.at<precision>(0, 0) = rotation.at<precision>(0, 0);
    modelview.at<precision>(1, 0) = rotation.at<precision>(1, 0);
    modelview.at<precision>(2, 0) = rotation.at<precision>(2, 0);
    modelview.at<precision>(3, 0) = 0;

    modelview.at<precision>(0, 1) = rotation.at<precision>(0, 1);
    modelview.at<precision>(1, 1) = rotation.at<precision>(1, 1);
    modelview.at<precision>(2, 1) = rotation.at<precision>(2, 1);
    modelview.at<precision>(3, 1) = 0;

    modelview.at<precision>(0, 2) = rotation.at<precision>(0, 2);
    modelview.at<precision>(1, 2) = rotation.at<precision>(1, 2);
    modelview.at<precision>(2, 2) = rotation.at<precision>(2, 2);
    modelview.at<precision>(3, 2) = 0;

    modelview.at<precision>(0, 3) = translation.at<precision>(0, 0);
    modelview.at<precision>(1, 3) = translation.at<precision>(1, 0);
    modelview.at<precision>(2, 3) = translation.at<precision>(2, 0);
    modelview.at<precision>(3, 3) = 1;

    // This matrix corresponds to the change of coordinate systems.
    static double changeCoordArray[4][4] = { { 1, 0, 0, 0 },{ 0, -1, 0, 0 },{ 0, 0, -1, 0 },{ 0, 0, 0, 1 } };
    static Mat changeCoord(4, 4, CV_64FC1, changeCoordArray);

    modelview = changeCoord*modelview;
}


void calibrate(Mat &intrinsic_Matrix, Mat &distortion_coeffs)
{

    vector< vector< Point2f> > AllimagePoints;
    vector< vector< Point3f> > AllobjectPoints;
    char str[100];
    stringstream st;
    int no_of_images = 1;
    Size imagesize;
    Mat gray;
    while (no_of_images <= 14)
    {
        st << "E:/SelectedImages/Selected" << ++no_of_images << ".jpg";
        String strcopy3 = st.str();
        st.str("");
        Mat img = imread(strcopy3, 1);
        if (!img.data)
            break;
        imagesize = Size(img.rows, img.cols);
        cvtColor(img, gray, CV_RGB2GRAY);
        vector< Point2f> corners;
        bool sCorner = false;
        sCorner = findChessboardCorners(gray, Size(7, 7), corners);
        if (sCorner)
        {

            cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
            drawChessboardCorners(img, Size(7, 7), corners, sCorner);
            if (corners.size() == 7 * 7)
            {
                vector< Point2f> v_tImgPT;
                vector< Point3f> v_tObjPT;
                for (int j = 0; j< corners.size(); ++j)
                {
                    Point2f tImgPT;
                    Point3f tObjPT;

                    tImgPT.x = corners[j].x;
                    tImgPT.y = corners[j].y;

                    tObjPT.x = j % 7 * 3;
                    tObjPT.y = j / 7 * 3;
                    tObjPT.z = 0;

                    v_tImgPT.push_back(tImgPT);
                    v_tObjPT.push_back(tObjPT);
                }
                AllimagePoints.push_back(v_tImgPT);
                AllobjectPoints.push_back(v_tObjPT);
            }

        }
        st << "E:/DetectedImages/Detected" << no_of_images + 1 << ".jpg";
        String strcopy1 = st.str();
        st.str("");
        imwrite(strcopy1, img);
        //imshow("pattern",img);
        //cvWaitKey(30);
    }
    vector< Mat> rvecs, tvecs;
    if (AllimagePoints.size()>0)
    {
        calibrateCamera(AllobjectPoints, AllimagePoints, imagesize, intrinsic_Matrix, distortion_coeffs, rvecs, tvecs);
    }

}


void renderBackgroundGL(const cv::Mat& image)
{

    GLint polygonMode[2];
    glGetIntegerv(GL_POLYGON_MODE, polygonMode);
    glPolygonMode(GL_FRONT, GL_FILL);
    glPolygonMode(GL_BACK, GL_FILL);


    glLoadIdentity();
    gluOrtho2D(0.0, 1.0, 0.0, 1.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    static bool textureGenerated = false;
    static GLuint textureId;
    if (!textureGenerated)
    {
        glGenTextures(1, &textureId);

        glBindTexture(GL_TEXTURE_2D, textureId);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

        textureGenerated = true;
    }

    // Copy the image to the texture.
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size().width, image.size().height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image.data);

    // Draw the image.
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_TRIANGLES);
    glNormal3f(0.0, 0.0, 1.0);

    glTexCoord2f(0.0, 1.0);
    glVertex3f(0.0, 0.0, 0.0);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(0.0, 1.0, 0.0);
    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, 0.0, 0.0);

    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, 0.0, 0.0);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(0.0, 1.0, 0.0);
    glTexCoord2f(1.0, 0.0);
    glVertex3f(1.0, 1.0, 0.0);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    // Clear the depth buffer so the texture forms the background.
    glClear(GL_DEPTH_BUFFER_BIT);

    // Restore the polygon mode state.
    glPolygonMode(GL_FRONT, polygonMode[0]);
    glPolygonMode(GL_BACK, polygonMode[1]);
}




void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    namedWindow("live", 1);
    Mat gray1, test, modelview, dis_img, thresh, img1;

    Mat rvec(3, 1, DataType<double>::type);
    Mat tvec(3, 1, DataType<double>::type);

    modelview.create(4, 4, CV_64FC1);
    //Projection.create(4, 4, CV_64FC1);

    vector< Point2f> corners1;
    vector< Point2f> imagePoints1;
    vector< Point3f> objectPoints1;
    largest_area = 0;
    largest_contour_index = 0;

    clock_t clock_1 = clock();
    cap >> dis_img;
    //resize(dis_img,dis_img,Size(180,180),0,0);
    if (!dis_img.data)
    {
        exit(3);
    }
    img1 = dis_img.clone();
    dis_img.copyTo(img1);
    //resize(img1,img1,Size(180,180),0,0);
    cvtColor(dis_img, dis_img, COLOR_BGR2YCrCb);
    inRange(dis_img, Scalar(0, 133, 77), Scalar(255, 173, 127), thresh);
    clock_t clock_2 = clock();
    cout << "threshold(Skin Color Segmentation) time is :" << (double)(clock_2 - clock_1) << endl;
    dilate(thresh, thresh, Mat());
    blur(thresh, thresh, Size(5, 5), Point(-1, -1), BORDER_DEFAULT);
    vector<vector<Point>> contours;
    vector<Point> FingerTips;
    vector<Vec4i> hierachy;
    vector<Vec4i> defects;
    vector<Point> defect_circle;
    vector<vector<Point>> hull(1);
    Point2f  center;
    float radius;
    clock_t clock_3 = clock();
    cout << "image filtering (smoothing) time is :" << (double)(clock_3 - clock_2) << endl;


    findContours(thresh, contours, hierachy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
    //cout<<"contour"<<endl; 
    int cont_size = contours.size();
    for (int i = 0; i<cont_size; i++)
    {
        double a = contourArea(contours[i], false);
        if (a>largest_area)
        {
            largest_area = a;
            largest_contour_index = i;
        }
    }

    vector<int> hull_index;
    Rect brect;

    if (largest_area>0 && contours[largest_contour_index].size()>5)
    {

        approxPolyDP(contours[largest_contour_index], contours[largest_contour_index], 8, true);
        //cout<<"approx_poly"<<endl;
        convexHull(Mat(contours[largest_contour_index]), hull[0], false, true);
        //  cout<<"convex_hull"<<endl;
        brect = boundingRect(contours[largest_contour_index]);
        //cout<<"bounding_rect"<<endl;
        convexHull(Mat(contours[largest_contour_index]), hull_index, true);
        //cout<<"convex_hull2"<<endl;
        convexityDefects(contours[largest_contour_index], hull_index, defects);
        //cout<<"convexity defect"<<endl;
        // Mom ents mom=moments(contours[largest_contour_index]);
        // draw mass center
        //  circle(img,Point(mom.m10/mom.m00,mom.m01/mom.m00),2,cv::Scalar(0),2);


        Scalar colorw = Scalar(0, 255, 0);
        Scalar color1 = Scalar(0, 0, 255);
        //drawContours(img,contours,largest_contour_index,color,2, 8, hierachy);
        //drawContours(timg,contours,largest_contour_index,color,1, 8, hierachy);
        //drawContours(timg, hull, 0, color1, 1, 8, vector<Vec4i>(), 0, Point() );
        //  drawContours(img, hull, 0, color1, 2, 8, vector<Vec4i>(), 0, Point() );
        int defc_size = defects.size();

        Point ptStart;
        Point ptEnd;
        Point ptStart2;
        Point ptEnd2;
        Point ptFar;
        int count = 1;
        int startidx2;
        int endidx2;
        int tolerance = brect.height / 5;
        float angleTol = 95;
        for (int in = 0; in<defc_size; in++)
        {
            //Vec4i& v=(*d); d++;
            int startidx = defects[in].val[0]; ptStart = contours[largest_contour_index].at(startidx);
            int endidx = defects[in].val[1]; ptEnd = contours[largest_contour_index].at(endidx);
            int faridx = defects[in].val[2];  ptFar = contours[largest_contour_index].at(faridx);
            if (in + 1<defc_size)
                startidx2 = defects[in + 1].val[0]; ptStart = contours[largest_contour_index].at(startidx);
            endidx2 = defects[in + 1].val[1]; ptEnd = contours[largest_contour_index].at(endidx);

            if (distanceP2P(ptStart, ptFar) > tolerance && distanceP2P(ptEnd, ptFar) > tolerance && getAngle(ptStart, ptFar, ptEnd) < angleTol) {
                {
                    if (in + 1<defc_size)
                    {
                        if (distanceP2P(ptStart, ptEnd2) < tolerance)
                            contours[largest_contour_index][startidx] = ptEnd2;
                        else {
                            if (distanceP2P(ptEnd, ptStart2) < tolerance)
                                contours[largest_contour_index][startidx2] = ptEnd;

                        }
                    }
                    defect_circle.push_back(ptFar);
                    //  cout<<"ptfar"<<ptFar.x<<"&&"<<ptFar.y<<endl;

                    if (count == 1)
                    {
                        FingerTips.push_back(ptStart);
                        cv::circle(img1, ptStart, 2, Scalar(0, 255, 0), 2);
                        putText(img1, intToString(count), ptStart - Point(0, 30), FONT_HERSHEY_PLAIN, 1.2f, Scalar(255, 0, 0), 2);
                    }
                    FingerTips.push_back(ptEnd);
                    count++;
                    putText(img1, intToString(count), ptEnd - Point(0, 30), FONT_HERSHEY_PLAIN, 1.2f, Scalar(255, 0, 0), 2);
                    cv::circle(img1, ptEnd, 2, Scalar(0, 255, 0), 2);
                    //cv::circle( img, ptFar,   2, Scalar(255,255,255 ), 2 );

                }
            }
        }
        //  circle(img, ptStart,2,Scalar(0xFF,0x60,0x02 ), 2, 8, 0 );

        //cv::circle( img, ptEnd,   4, Scalar( 0xFF,0x60,0x02 ), 2 );
        clock_t clock_4 = clock();
        cout << "fingerTip detection  time is :" << (double)(clock_4 - clock_3) << endl;

        //  cout<<"hii"<<endl;
        bool two_fn = false;
        bool five_fn = false;

        if (defect_circle.size() == 1)
        {
            two_fn = true;
            Point fn = FingerTips.back();
            FingerTips.pop_back();
            Point ln = FingerTips.back();
            FingerTips.pop_back();
            Point defect_point = defect_circle.back();
            float curr = getAngle(fn, defect_point, ln);
            curr = curr / 10;
            curr = 10 - curr;
            renderBackgroundGL(img1);
            objectPoints1.push_back(Point3d(9, 6, 0));
            imagePoints1.push_back(defect_point);

            objectPoints1.push_back(Point3d(9, 6, 0));
            imagePoints1.push_back(defect_point);



            objectPoints1.push_back(Point3d(19, 6, 0));
            imagePoints1.push_back(fn);

            objectPoints1.push_back(Point3d(9, 18, 0));
            imagePoints1.push_back(ln);


            // cout<<width<<"  &"<<height<<endl;
            //  cout<<"solvepnp"<<endl; 
            solvePnP(Mat(objectPoints1), Mat(imagePoints1), intrinsic_Matrix, distortion_coeffs, rvec, tvec);



            cv::Mat rotation;
            cv::Rodrigues(rvec, rotation);
            double offsetA[3][1] = { 9,6,6 };
            Mat offset(3, 1, CV_64FC1, offsetA);
            tvec = tvec + rotation*offset;


            generateProjectionModelview(intrinsic_Matrix, rotation, tvec, Projection, modelview);
            glMatrixMode(GL_PROJECTION);
            GLfloat* projection = convertMatrixType(Projection);
            glLoadMatrixf(projection);
            delete[] projection;

            glMatrixMode(GL_MODELVIEW);
            GLfloat* modelView = convertMatrixType(modelview);
            glLoadMatrixf(modelView);
            delete[] modelView;

            //glTranslatef(0.0f,0.0f,-5.0f);
            glPushMatrix();
            glColor3f(1.0, 0.0, 0.0);

            glutWireTeapot(10.0 / curr);
            glPopMatrix();
            glColor3f(1.0, 1.0, 1.0);

        }
        //Rotation Module
        if (defect_circle.size() == 4)
        {

            five_fn = true;
            minEnclosingCircle(defect_circle, center, radius);
            //circle(img, center, (int)radius,Scalar(255,255,255), 2, 8, 0 );
            circle(img1, center, 2, Scalar(0), 2, 8, 0);

            vector<pair<float, Point>> pos;
            for (int in = 0; in<FingerTips.size(); in++)
            {
                Point p = FingerTips.back();
                FingerTips.pop_back();

                //if(in==0)
                //{
                pos.push_back(make_pair(distanceP2P(center, p), p));
                //position.push_back(pos);
            }
            //  }
            //else
            //  {
            //      cout<<"size is"<<position.size()<<endl;
            //  position[n].push_back(make_pair(distanceP2P(center,p),p));
            //}

            sort(pos.begin(), pos.end(), pairCompare);
            //  vector<pair<float,Point>> now=position[i].back();
            first = pos.back().second;
            pos.pop_back();
            //cout<<"new value :"<<new1.x<<" && "<<new1.y<<endl;
            second = pos.back().second;
            pos.pop_back();
            third = pos.back().second;
            pos.pop_back();

            if (third.y<second.y&&second.y<first.y)
            {
                //  cout<<"vertical pose"<<endl;
                FIX_X.x = center.x + 40;
                FIX_X.y = center.y;

                FIX_Y.x = center.x;
                FIX_Y.y = center.y - 40;
            }
            skew_x = getAngle(first, center, FIX_X);
            skew_y = getAngle(third, center, FIX_Y);
            cout << skew_x << "&" << skew_y << endl;
            if (first.x<img1.cols)
                line(img1, center, first, Scalar(200, 200, 200), 2, 8, 0);
            line(img1, center, FIX_X, Scalar(200, 200, 200), 2, 8, 0);
            if (second.x<img1.cols)
                line(img1, center, second, Scalar(0, 255, 0), 2, 8, 0);
            if (third.x<img1.cols)
                line(img1, center, third, Scalar(0, 0, 255), 2, 8, 0);
            line(img1, center, FIX_Y, Scalar(0, 0, 255), 2, 8, 0);

            //  line(img1,center,first,Scalar(255,255,255),2,8,0);
            //  line(img1,center,second,Scalar(0,255,255),2,8,0);
            //  line(img1,center,third,Scalar(0,0,255),2,8,0);

            renderBackgroundGL(img1);

            /*  cvtColor(test, gray1, CV_RGB2GRAY);
            bool sCorner1=findChessboardCorners(gray1, Size(7, 7), corners1);
            imshow("live",test);
            if(sCorner1)
            {
            cornerSubPix(gray1, corners1, Size(11,11), Size(-1,-1), TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1));
            if(corners1.size() == 7*7)
            {control pan

            for(int j=0; j< corners1.size(); ++j)
            {
            Point2f tImgPT;
            Point3f tObjPT;

            tImgPT.x = corners1[j].x;
            tImgPT.y = corners1[j].y;

            tObjPT.x = j%7*3;
            tObjPT.y = j/7*3;
            tObjPT.z = 0;
            imagePoints1.push_back(tImgPT);
            objectPoints1.push_back(tObjPT);
            }

            vector<Point2f> projectedPoints;
            vector<Point3f> axis;

            axis.push_back(Point3f(6,0,0));
            axis.push_back(Point3f(0,6,0));
            axis.push_back(Point3f(0,0,6));  */
            objectPoints1.push_back(Point3d(9, 6, 0));
            imagePoints1.push_back(center);

            objectPoints1.push_back(Point3d(9, 18, 0));
            imagePoints1.push_back(first);

            objectPoints1.push_back(Point3d(19, 6, 0));
            imagePoints1.push_back(third);

            objectPoints1.push_back(Point3d(15, 15, 0));
            imagePoints1.push_back(second);


            // cout<<width<<"  &"<<height<<endl;
            //  cout<<"solvepnp"<<endl; 
            solvePnP(Mat(objectPoints1), Mat(imagePoints1), intrinsic_Matrix, distortion_coeffs, rvec, tvec);



            cv::Mat rotation;
            cv::Rodrigues(rvec, rotation);
            double offsetA[3][1] = { 9,6,0 };
            Mat offset(3, 1, CV_64FC1, offsetA);
            tvec = tvec + rotation*offset;


            generateProjectionModelview(intrinsic_Matrix, rotation, tvec, Projection, modelview);

            /*  double offsetA[3][1] = {{(7-1.0)/2.0}, {(7-1.0)/2.0}, {0}};
            Mat offset(3, 1, CV_64FC1, offsetA);
            tvec = tvec + rotation*offset;

            for(unsigned int row=0; row<3; ++row)
            {
            for(unsigned int col=0; col<3; ++col)
            {
            modelview.at<float>(row, col) = rotation.at<float>(row, col);
            cout<<modelview.at<float>(row,col)<<endl;
            }
            modelview.at<float>(row, 3) = tvec.at<float>(row, 0);
            }
            modelview.at<float>(3, 3) = 1.0f;
            cout<<endl;



            static float changeCoordArray[4][4] = {{-1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}};
            static Mat changeCoord(4, 4, CV_64FC1, changeCoordArray);

            modelview = changeCoord*modelview;

            cv::Mat glmodelview = cv::Mat::zeros(4, 4, CV_64F);
            transpose(modelview , glmodelview);
            gluLookAt(0.0,2.0,-50.0,0.0,0.5,0.0,0.0,1.0,0.0);
            /*  glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            float fx=intrinsic_Matrix.at<float>(0,0);
            float fy=intrinsic_Matrix.at<float>(1,1);
            float cf=(2*atanf(0.5*height/fy)*180/3.14);
            float aspect=(width*fy)/(height*fx);

            //gluPerspective(cf,1.0, zNear, zFar);



            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            glLoadMatrixf(&glmodelview.at<float>(0,0));  */
            glMatrixMode(GL_PROJECTION);
            GLfloat* projection = convertMatrixType(Projection);
            glLoadMatrixf(projection);
            delete[] projection;

            glMatrixMode(GL_MODELVIEW);
            GLfloat* modelView = convertMatrixType(modelview);
            glLoadMatrixf(modelView);
            delete[] modelView;

            //glTranslat ef(0.0f,0.0f,-5.0f);
            glPushMatrix();
            glColor3f(1.0, 0.0, 0.0);
            glRotatef(skew_x, 1.0, 0.0, 0.0);
            glRotatef(skew_y, 0.0, 1.0, 0.0);
            glutWireTeapot(10.0);
            glPopMatrix();
            glColor3f(1.0, 1.0, 1.0);
            clock_t clock_5 = clock();
            cout << "interaction time is :" << (double)(clock_5 - clock_4) << endl;
        }
        imshow("live", img1);
        cout << "----------------------------------------------" << endl;

        glFlush();
        glutSwapBuffers();
    }
    waitKey(27);
    glutPostRedisplay();
}
void reshape(int x, int y)
{
    width = x; height = y;
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    /*Projection.at<float>(0,0) = 2*intrinsic_Matrix.at<float>(0,0)/width;
    Projection.at<float>(1,0) = 0;
    Projection.at<float>(2,0) = 0;
    Projection.at<float>(3,0) = 0;

    Projection.at<float>(0,1) = 0;
    Projection.at<float>(1,1) = 2*intrinsic_Matrix.at<float>(1,1)/height;
    Projection.at<float>(2,1) = 0;
    Projection.at<float>(3,1) = 0;

    Projection.at<float>(0,2) = 1-2*intrinsic_Matrix.at<float>(0,2)/width;
    Projection.at<float>(1,2) = -1+(2*intrinsic_Matrix.at<float>(1,2)+2)/height;
    Projection.at<float>(2,2) = (zNear+zFar)/(zNear - zFar);
    Projection.at<float>(3,2) = -1;

    Projection.at<float>(0,3) = 0;
    Projection.at<float>(1,3) = 0;
    Projection.at<float>(2,3) = 2*zNear*zFar/(zNear - zFar);
    Projection.at<float>(3,3) = 0;

    cv::Mat projection = cv::Mat::zeros(4, 4, CV_64F);
    transpose(Projection ,projection);
    glLoadMatrixf(&projection.at<float>(0,0));   */


    // gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0); 

    /* float fx=intrinsic_Matrix.at<float>(0,0);
    float fy=intrinsic_Matrix.at<float>(1,1);
    float cf=(2*atanf(0.5*height/fy)*180/3.14);
    cout<<fx<<"   "<<fy<<endl;
    float aspect=(width*fy)/(height*fx);  */
    //gluPerspective(cf,CALIB_FIX_ASPECT_RATIO, zNear, zFar); 


    //glMatrixMode(GL_MODELVIEW);
    //  gluPerspective(60,width/height, zNear, zFar);  
    //glOrtho(-100,100,-100.0,100,zNear, zFar);

}
void init()
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void main()
{
    if (!cap.isOpened())
    {
        exit(-1);
    }
    cap >> test;
    if (!test.data)
    {
        exit(-1);
    }
    //  resize(test,test,Size(180,180),0,0);
    width = test.cols;
    height = test.rows;
    cout << width << endl;
    calibrate(intrinsic_Matrix, distortion_coeffs);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(width, height);
    glutCreateWindow("code4change");
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
}

But when i compile the cide it always get error message «Cannot open include file: ‘stdafx.h'».What should i do?.As i know stdafx.h is a c++ headerfile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
 
using namespace std;
 
int getIntZodiak(char * str); // прототип функции, которая возвращает порядковый номер знака зодиака
 
struct Znak
{
    char name[50]; // фамилия, имя
    char zodiac[20]; // знак зодиака
    int bday[3]; // дата рождения дд.мм.гг
};
 
// массив указателей на строки (знаки зодиака)
const char *sign_zodiac[12] = {"Овен", "Телец", "Близнецы", "Рак" , "Лев", "Дева",
                         "Весы", "Скорпион", "Стрелец", "Козерог", "Водолей", "Рыбы" }; // порядок следования знаков зодиака
int main()
{
    const int size_array = 8; // количество записей
    Znak book[size_array]; // объявляем массив структур
    int counter_rec = 0; // счётчик записей
 
    while (counter_rec < size_array) // пока не внесено 8 записей
    {
        cout << "Введите имя и фамилию через пробел: ";
        cin.getline(book[counter_rec].name, 50);
 
        cout << "Введите знак зодиака: ";
        cin.getline(book[counter_rec].zodiac, 20);
 
        cout << "Введите дату рождения в формате (дд.мм.гг) ";
        cin >> setw(2) >> (book[counter_rec].bday[0]); // считать первые два символа, т.е. день
        cin.ignore(); // пропустить символ точки
        cin >> setw(2) >> book[counter_rec].bday[1]; // считать следующие два символа, т.е. месяц
        cin.ignore(); // пропустить символ точки
        cin >> setw(4) >> book[counter_rec].bday[2]; // считать четыре символа, т.е. год
        cin.get(); // считываем символ новой строки 'n'
 
        counter_rec++; // инкремент счётчика записей
    }
 
    // сортировка записей в массиве структур
    for (int ctr1 = 0; ctr1 < size_array; ctr1++)
    {
        for (int ctr2 = ctr1 + 1; ctr2 < size_array; ctr2++)
        {
            if (getIntZodiak(book[ctr1].zodiac) > getIntZodiak(book[ctr2].zodiac)) // если порядок не правильный, то поменять местами записи
            {
                char temp_name[50]; // временная переменная для перестановки строк: имя и знак зодиака
 
                // перестановка имён
                strcpy(temp_name, book[ctr1].name);
                strcpy(book[ctr1].name, book[ctr2].name);
                strcpy(book[ctr2].name, temp_name);
 
                // перестановка знака зодиака
                strcpy(temp_name, book[ctr1].zodiac);
                strcpy(book[ctr1].zodiac, book[ctr2].zodiac);
                strcpy(book[ctr2].zodiac, temp_name);
 
                int temp_data[3] = {book[ctr1].bday[0], book[ctr1].bday[1], book[ctr1].bday[2]}; // временный массив, для обмена д.р.
 
                // перестановка дат рождения
                book[ctr1].bday[0] = book[ctr2].bday[0];
                book[ctr1].bday[1] = book[ctr2].bday[1];
                book[ctr1].bday[2] = book[ctr2].bday[2];
                book[ctr2].bday[0] = temp_data[0];
                book[ctr2].bday[1] = temp_data[1];
                book[ctr2].bday[2] = temp_data[2];
 
            }
        }
    }
 
    int month = 0;
    cout << "Введите порядковый номер месяца: ";
    cin >> month;
    if (month < 1 || month > 12)
    {
        cout << "Месяц указан не корректно!" << endl;
                //return -1;
    }
    else
    {
        // печать записей, месяц которых совпадает с введённым
        cout << endl;
        bool no_records = false; // переменная-флаг, отвечающая за существование записей, месяц которых равен введённому
        for (int counter = 0; counter < size_array; counter++)
        {
            if (book[counter].bday[1] == month) // если совпадает номер месяца в записи с введённым с клавиатуры
            {
                no_records = true;
                cout << book[counter].name << endl; // имя и фамилия
                cout << book[counter].zodiac << endl; // знак зодиака
                cout << setfill('0') << setw(2) << book[counter].bday[0] << "."
                     << setw(2) << book[counter].bday[1] << "." << setw(2) << book[counter].bday[2] << endl << endl; // дата рождения
            }
        }
        if (no_records) cout << "Нет людей родившихся " << month << " месяца." << endl;
    }
    return 0;
}
 
int getIntZodiak(char * str) // функция возвращает порядковый номер знака зодиака
{
    for (int counter = 0; counter < 12; counter++)
    {
        if (!strcmp(str,sign_zodiac[counter])) // если знаки зодиака совпадают, то вернуть порядковый номер
            return counter;
    }
  return -1; // возвращаемое значение, в случае, если имя передоваемое как параметр не совпало ни с одним знаком зодиака
}
  1. Тему во флуд чтобы форум не ругался!
    Прошу не кидаться помидорами!
    Я новичок в С++ на пк , Раньше токо на ардуино писал.
    Работаю на dev c++.
    Проблема которая запрещена к рассуждению на многих форумах.
    Она это «stdafx.h no such file or directory» .
    Я понимаю что глупый вопрос.
    Но как избежать этой проблемы без постоянного std::

    #include «stdafx.h»
    #include «iostream»
    #include «clocale»
    using namespce std;
    int main()
    {
        setlocale(LC_ALL, «Russian»);
        const int n = 101;
        char name[n], line[n];
        cout << «S:» << endl << endl;
        cin.getline(name, n);
        cout << endl;
        ifstream fin(«d:\mybaza.txt»);
        if (!fin) { cout << «ERROR! File no found!» << endl; system(«PAUSE»); return 1;}
        while (fin.getline(line, n)){
            if (strstr(line, name)) {cout << line << endl; }
        }
        cout << endl;
        system(«PAUSE»);
        return 0;
    }

    Код не мой — Пример отсюда http://olocoder.ru/C24.html
    Помогите пожалуйста!

  2. Если не пользуетесь этой системой, то не подключайте файл.
    Не понял связи с std::

  3. Ну вообще-то есть директива using namespace, почитайте, зачем она нужна — как раз для того, чтобы неймспейсы не писать по каждому чиху.

  4. cout не работает без using namespace std а using namespace std не работает без строки #include «stdafx.h»
    но это не мой код а пример от сюда http://olocoder.ru/C24.html

    Последнее редактирование: 7 дек 2017

  5. и даже если сделать

    //#include «stdafx.h»
    #include «iostream»
    #include «clocale»
    //using namespce std;
    int main()
    {
        setlocale(LC_ALL, «Russian»);
        const int n = 101;
        char name[n], line[n];
        std::cout << «S:» << std::endl << std::endl;
        std::cin.getline(name, n);
        std::cout << std::endl;
        //ifstream fin(«d:\mybaza.txt»);
       // if (!fin) { std::cout << «ERROR! File no found!» << std::endl; system(«PAUSE»); return 1;}
      //  while (fin.getline(line, n)){
      //      if (strstr(line, name)) {std::cout << line << endl; }
       // }
       // std::cout << std::endl;
        //system(«PAUSE»);
        return 0;
    }

    а не

    #include «stdafx.h»
    #include «iostream»
    #include «clocale»
    using namespce std;
    int main()
    {
        setlocale(LC_ALL, «Russian»);
        const int n = 101;
        char name[n], line[n];
        cout << «S:» << endl << endl;
        cin.getline(name, n);
        cout << endl;
        ifstream fin(«d:\mybaza.txt»);
        if (!fin) { cout << «ERROR! File no found!» << endl; system(«PAUSE»); return 1;}
        while (fin.getline(line, n)){
            if (strstr(line, name)) {cout << line << endl; }
        }
        cout << endl;
        system(«PAUSE»);
        return 0;
    }
  6. ну вообще то она у меня стоит в изначальном коде

    который тоже неработает хотя взят пример

  7. 1    20    C:UsersÈÊÑDocumentspoisk.cpp    [Error] stdafx.h: No such file or directory
    compilation terminated.
    28        C:UsersÈÊÑDocumentsMakefile.win    recipe for target ‘poisk.o’ failed
     

    это та ошибка с которой я пришол

  8. вот код из примера

    #include «stdafx.h»
    #include «iostream»
    #include «clocale»
    using namespce std;
    int main()
    {
    setlocale(LC_ALL, «Russian»);
    const int n = 101;
    char name[n], line[n];   // line õðàíèò â ñåáå ïðîâåðÿþùóþñÿ ñòðîêó
    cout << «Ââåäèòå ôàìèëèþ:» << endl << endl;
    cin.getline(name, n);
    cout << endl;
    ifstream fin(«d:\mybaza.txt»);   // îòêðûâàåì ôàéë
    if (!fin) { cout << «ERROR! File no found!» << endl; system(«PAUSE»); return 1;}
    while (fin.getline(line, n)){
    if (strstr(line, name)) {cout << line << endl; }
    }
    cout << endl;
    system(«PAUSE»);
    return 0;
    }
  9. Вы чего хотите-то? Чтобы сторонний код, сделанный под одной средой разработки, скомпилировался под другой средой разработки? Тогда решайте — пробуйте закомментировать подключение stdafx.h, смотрите, на что ругается, анализируйте. Судя по ошибкам — там ещё и с мейкфайлом проблемы. По телефону такие вещи, как правило, не лечатся.

    Код тривиальный, его можно и самому с нуля переписать, создав консольный проект в вашей IDE — думаю, это будет лучшим вариантом.

  10. Как работает, когда у вас вообще #include «stdafx.h» не работает? Может подумаете еще?

  11. Простите… но так и не понял: Вы решили проблему? Или вопрос актуален? Но пример от Visual Studio. А у Microsoft всегда всё по своему.

  12. Здравствуйте,

    нет

    не очень — сечас нету времени

    ну это понятно

    Спасибо за ответ

  13. Будьте внимательнее:

    а надо:

    Потребовалось запускать виртуальную машину с Windows и VisualStudio… реальных Windows не держу. Сразу и сам не заметил.

  14. Вот попробуйте:

    //#include «stdafx.h»
    #include <stdio.h>
    #include <tchar.h>
    #include <iostream>
    #include <fstream>
    #include <clocale>
    using namespace std;

    int main()
    {
        setlocale(LC_ALL, «Russian»);
        const int n = 101;
        char name[n], line[n];
        cout << «S:» << endl << endl;
        cin.getline(name, n);
        cout << endl;
        ifstream fin(«d:\mybaza.txt»);
        if (!fin) { cout << «ERROR! File no found!» << endl; system(«PAUSE»); return 1;}
        while (fin.getline(line, n)){
            if (strstr(line, name)) {cout << line << endl; }
        }
        cout << endl;
        system(«PAUSE»);
        return 0;
    }

    Понятно заголовочные (#include <file>) надо поставить вручную… как тут. Тестировал в Visual Studio 2005. В настройках проекта вот это:

    Снимок28.JPG

please help me….

me all the time that error occurs, look after the forums but not found out what this is about

this is code:

#include «stdafx.h»
#include <iostream>
/*
#include <stdlib.h>

#include <stdio.h>

#include <ctype.h>

#include <string.h>

#include <time.h>

#include «randomcard.h»
*/

# define CLANOVI_OBITELJI 100
# define MJESECI 100

using namespace std;

int main(){
    float dzeparci[CLANOVI_OBITELJI][MJESECI];
    float dzeparci_po_clanu[CLANOVI_OBITELJI];
    float dzeparci_po_mjesecu[MJESECI];

    int br_clanova,br_mjeseci;

    cout<<«Unesi broj clanova obitlji: «;
    cin>>br_clanova;
    cout<<«Unesi broj mjeseci: «;
    cin>>br_mjeseci;

    for(int i=0; i<br_clanova; i++){
        cout<<«n»<<i+1<<«. CLAN OBITELJI»<<endl;
        for(int j=0; j<br_mjeseci; j++){
            cout<<j+1<<«. mjesec: «;
            cin>>dzeparci[i][j];
        }
    }

    float zbroj_dzeparca=0;
    for(int i=0; i<br_clanova; i++){
        zbroj_dzeparca=0;
        for(int j=0; j<br_mjeseci; j++){
            zbroj_dzeparca += dzeparci[i][j];
        }
        dzeparci_po_clanu[i] = zbroj_dzeparca/br_mjeseci;
    }

        for(int i=0; i<br_mjeseci; i++){
    zbroj_dzeparca=0;
    for(int j=0; j<br_clanova; j++){
        zbroj_dzeparca += dzeparci[j][i];
    }
    dzeparci_po_mjesecu[i] = zbroj_dzeparca/br_clanova;
}
cout<<«DZEPARCI»<<endl;
for(int i=0; i<br_clanova; i++){
    cout<<i+1<<«. CLAN:»;
    for(int j=0; j<br_mjeseci; j++){
        cout<<«t»<<dzeparci[i][j];
    }
    cout<<endl;
}

cout<<«PROSJECNI DZEPARAC PO CLANU OBITELJI»<<endl;
for(int i=0; i<br_clanova; i++){
    cout<<i+1<<«. CLAN:t»<<dzeparci_po_mjesecu[i]<<endl;
}
return 0;
}

thx

In VSC++, If I create a project with «Empty project» which is without «Precompiled header», the project will be empty, but if I wanted to use that #include "stdafx.h" inside my «Empty» project, it doesn’t works…

but if I create a project with «Precompiled header», it can work fine.

both the condition above having exactly the same code(Both have #include "stdafx.h" ), but only the one with «Precompile header» Project can work…

May I know how to solve this problem in «Empty Project»??

This is the error when creating the project in «Empty Project»

fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1>

lastly, Can I know what is #include "stdafx.h" for? Thanks…

but if I wanted to use that #include «stdafx.h» inside my «Empty» project, it doesn’t works…

Of course not. stdafx is the precompiled header. If you don’t have a precompiled header, then how can you include it?

May I know how to solve this problem in «Empty Project»??

It’s not really a problem. Just don’t include that header.

Or if you must (if you have dozens of files and you don’t want to modify them all), you can «fake» it by creating a blank file named «stdafx.h».

Can I know what is #include «stdafx.h» for?

When you #include a header file, it’s sort of like copy/pasting that header file into the cpp file. The compiler will walk through, examine, and compile that header whenever you compile the cpp file.

The compiler will do this process for every cpp file that includes that header. So if you have 100 cpp files in your project and they all include the same header, that header is being compiled 100 times.

If the header is very large, this might cause the computer to take a long time to compile your program. So compilers give you an option to «precompile» a header so that it compiles only once. Then each cpp file that #includes it does not have to re-compile it every time, they can just use the precompiled version. It can speed up compile time.

MSVS likes to name the default precompiled header «stdafx.h». But that’s all it is.

It’s worth noting that precompiled headers are completely worthless unless you are seeing slow compile times. I avoid them unless they make a significant difference in compile time.

Thanks…
Is that means #include "stdafx.h" is called precompiled header where as #include <iostream> , #include <conio.h> and so on is a library header? Or it’s call precompiled header as well?

From what u said, it’s completely worthless, is that means, without that #include "stdafx.h" , my system can works fine also?

Is that means #include «stdafx.h» is called precompiled header where as #include <iostream> , #include <conio.h> and so on is a library header?

Not really. A precompiled header can be named anything. «stdafx» is just the default name for it in VS.

Precompiling is a compiler setting. You can precompile any header, even library headers like <iostream>.

From what u said, it’s completely worthless, is that means, without that #include «stdafx.h» , my system can works fine also?

Yes. Enabling precompiled headers does absolutely nothing other than change how fast the compile can build the exe. The final program will be identical whether or not you use precompiled headers.

A precompiled header can be named anything.

If I named it as «ABC», it will works too?

Enabling precompiled headers does absolutely nothing other than change how fast the compile can build the exe.

U mean if have that #include "stdafx.h" , the system can build exe file faster? Is that what u mean? I though if we put more header, the time require to compile will be longer, am I right?

TQ….

If I named it as «ABC», it will works too?

Yes. The header can be named anything, as long as the compiler knows to precompile that header.

U mean if have that #include «stdafx.h» , the system can build exe file faster?

Yes, that’s the idea. Whether or not it REALLY makes it faster depends. Usually it won’t make much/any difference unless stdafx.h is a very big header.

I though if we put more header, the time require to compile will be longer, am I right?

Yes you are right.

Compile time is longer with more headers because the compiler had to compile each header when it is included.

However, if the headers are precompiled it doesn’t have to compile them because they have been precompiled already. Which is why it’s faster.

However, if the headers are precompiled it doesn’t have to compile them because they have been precompiled already. Which is why it’s faster.

But u said precompiled header has nothing to do with our program right? Then how to precompile my header since my header used is like #include <iostream> and #include <conio> but not #include "stdafx.h"

Is that u mean in one program, I use many (let said 3) #include <iostream> and #include <conio> and if I include that Precompile header (#include «stdafx.h»), then it runs #include <iostream> and #include <conio> only once instead of 3 is it?

And another condition is I use many(let said 3) #include <iostream> and #include <conio> , but not include that Precompile header (#include «stdafx.h») this time, so, is that mean my program will runs #include <iostream> and #include <conio> 3 times?

Yes, that’s the idea. Whether or not it REALLY makes it faster depends. Usually it won’t make much/any difference unless stdafx.h is a very big header.

U mean stdafx.h is a big header? That header can be big? I thought it’s just a constant header which is same size(won’t change) with everyone? And somehow, if header is bigger, the time to compile should be longer right? But why big header become faster? Not really understand…can u help explain…

TQ…

Last edited on

The basic idea of precompiled header is: once parsed, used ever after.

Everything in this precompiled header (definitions or other includes) are put together in a file that is used instead of the precompiled header (#include «stdafx.h») itself. It’s supposed to be faster, because the compiler doesn’t need to open those includes and no more parsing is required.

You can put everything that doesn’t change (like #include <iostream> and #include <conio>) in that precomiled header. Only the project specific headers are left out.

That’s the idea.

The problem is that the precompiled file quickly becomes that hugh that navigating within is not faster then opening and parsing the headers when needed. Plus it turns out that the precompiled header file is error prone and you get problems while compiling.

The best is to disable precompiled header and forget about that once and forever.

Thanks coder776,

You can put everything that doesn’t change (like #include <iostream> and #include <conio>) in that precomiled header. Only the project specific headers are left out.

From here, can I know how to put them #include <iostream> and #include <conio> inside precompiled header (#include «stdafx.h»)? Example to the code below, how to put that 2 header inside stdafx.h? Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <conio>

int main()
{
	int a,b,c;


   cin>>a;
   cin>>b;
   c=a+b;
   cout<<"The value c is n"<<c;
   getch();
   return 0;
}

Well, create a file in that directory where your main file is. Name it stdafx.h. Cut and copy line 1/2 to that file. the first line of your main file (and all other implementation files) must be #include «stdafx.h»

Thanks…

u mean create one main file which have the 1st line as #include «stdafx.h» and the next line will be the library header like the one below is it?

1
2
3
#include "stdafx.h"
#include <iostream>
#include <conio> 

how about the rest? I mean is there anything after line 3? Or just need line 1-3? TQ…

Last edited on

no I mean that you create a file stdafx.h and place #include <iostream> and #include <conio> there.

in the file stdafx.h there’re only the lines 2 and 3.

the main file is the file where ‘int main()’ is. I don’t know how you named it. This would look like so:

Your main file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "stdafx.h"

int main()
{
	int a,b,c;


   cin>>a;
   cin>>b;
   c=a+b;
   cout<<"The value c is n"<<c;
   getch();
   return 0;
}

stdafx.h

1
2
#include <iostream>
#include <conio> 

Last edited on

I think you’re missing some fundamental concept.

The compiler is going to parse and compile every included file every time it compiles a source file (which is every time you change a source file). So for an example, let’s say you have the following files:

1
2
3
4
// myclass.h
#include <string>

class MyClass {  /*... */ };

1
2
3
4
// stdafx.h
#include <windows.h>
#include <iostream>
#include "myclass.h" 

1
2
3
4
// main.cpp
#include "stdafx.h"

// ... 

1
2
3
4
// support.cpp
#include "stdafx.h"

//... 

When you build this project,

if you do not have a precompiled header

the compiler is going to compile the 2 source files main.cpp and support.cpp. When it does, it will do this:

Compiling main.cpp
— found #include «stdafx.h» in main.cpp, so start compiling stdafx.h
— found #include <windows.h> in stdafx.h, so start compiling windows.h
— found XXX other includes in windows.h, so compile all those headers as well
— found #include <iostream> in stdafx.h, so start compiling that header
— found XXX other includes in iostream, so compile all those as well
— found #include «myclass.h» in stdafx.h, so compile that header
— stdafx.h finish, continue compiling main.cpp

Compiling support.cpp
— found #include «stdafx.h» in support.cpp, so start compiling stdafx.h
— found #include <windows.h> in stdafx.h, so start compiling windows.h
— found XXX other includes in windows.h, so compile all those headers as well
— found #include <iostream> in stdafx.h, so start compiling that header
— found XXX other includes in iostream, so compile all those as well
— found #include «myclass.h» in stdafx.h, so compile that header
— stdafx.h finish, continue compiling support.cpp

Now…

if you make stdafx.h a precompiled header

, the compiler will do this instead:

PreCompiling stdafx.h
— found #include <windows.h> in stdafx.h, so start compiling windows.h
— found XXX other includes in windows.h, so compile all those headers as well
— found #include <iostream> in stdafx.h, so start compiling that header
— found XXX other includes in iostream, so compile all those as well
— found #include «myclass.h» in stdafx.h, so compile that header
— stdafx.h is now compiled, put compiled information in a new «stdafx.pch» file

Compiling main.cpp
— found #include «stdafx.h», but I already compiled that header, so no need to compile it again. Just use the info in the existing pch file.
— continue compiling main.cpp

Compiling support.cpp
— found #include «stdafx.h», but I already compiled that header, so no need to compile it again. Just use the info in the existing pch file.
— continue compiling support.cpp

That’s all it does. It just compiles the stuff once so it doesn’t need to be compiled every time.

Last edited on

Thanks coder777 and Disch

I think I understand already…

just another question for coder777, as u said

Well, create a file in that directory where your main file is. Name it stdafx.h. Cut and copy line 1/2 to that file. the first line of your main file (and all other implementation files) must be #include «stdafx.h»

first line of your main file (and all other implementation files) must be #include «stdafx.h»

is that must be 1st line? or any line before int main () are allow(maybe put the header after other library file) ? Is that ok? Thanks…

Понравилась статья? Поделить с друзьями:
  • Status da selection error 0xc0030003 flashtool ошибка
  • Status brom cmd fail 0xc0060005 ошибка flashtool
  • Status brom cmd fail 0xc0060003 ошибка flashtool
  • Status brom cmd fail 0xc0060001 ошибка flashtool
  • Status application hang ошибка в dayz как исправить