//#include <stdafx.h>
#include <iostream> //line_poly_file.cpp
#include <fstream>
#include <windows.h>
#include <glut.h>
GLsizei wh = 250;
GLsizei ww = 250;
void DisplayLines ( void ) ;
void MyInit ( ) ;
void DisplayLines ( void ) {
    GLint xj, yj, j;
    glClear ( GL_COLOR_BUFFER_BIT ) ;
    fstream inStream;
    //inStream.open("R.txt", ios ::in);
	inStream.open("R.txt", "r");
    if(!inStream) {
            cout << "File would not open\n";
            return;
        }
    glBegin(GL_LINE_STRIP); //render a series of vertices
    for (j=1; j<=7; j++) {
        inStream >> xj >> yj; //read from disc file
        cout << xj << " " << yj <<"\n";
        glVertex2i(xj,yj);
    }
glEnd();
glFlush();
}
void MyInit ( void ) {
    glClearColor ( 1.0, 1.0, 0.0, 0.0 );//set window buffer as yellow
    glColor3f(0.0f, 0.0f,1.0f); //draw R in blue
    //glLineWidth(5.0); //try different line thicknesses
    glMatrixMode ( GL_PROJECTION );
    glLoadIdentity ( ) ;
    gluOrtho2D ( 0.0, (GLdouble)ww, 0.0,(GLdouble)wh );
    //draw R in this space
}
void main(int argc, char **argv) {
    glutInit ( &argc, argv );
    glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB );
    glutInitWindowSize ( ww, wh );
    glutInitWindowPosition ( 150, 90 );
    glutCreateWindow ( "Display R" );
    MyInit ( );
    glutDisplayFunc ( DisplayLines );
    glutMainLoop ( );
}
Attachments
10 10
10 100
30 100
45 80
30 70
10 70
45 10

'fstream' : undeclared identifier
1>.\line_poly_file.cpp(13) : error C2146: syntax error : missing ';' before identifier 'inStream'
1>.\line_poly_file.cpp(13) : error C2065: 'inStream' : undeclared identifier
1>.\line_poly_file.cpp(15) : error C2228: left of '.open' must have class/struct/union
1> type is ''unknown-type''
1>.\line_poly_file.cpp(17) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\faiza\My Documents\Visual Studio 2005\Projects\line_poly_file\line_poly_file\Debug\BuildLog.htm"
1>line_poly_file - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

fstream is part of the std namespace. So either put using namespace std; or

using std::fstream;

along with others that you need to use.

He's saying to do this at the top of your code:

//#include <stdafx.h>
#include <iostream> //line_poly_file.cpp
#include <fstream>
#include <windows.h>
#include <glut.h>
using namespace std;     //Insert this new line right here!
GLsizei wh = 250;

Beyond that, I don't know how to help you much.

>.\line_poly_file.cpp(8) : error C2146: syntax error : missing ';' before identifier 'GLsizei'
1>.\line_poly_file.cpp(8) : error C2146: syntax error : missing ';' before identifier 'wh'
1>.\line_poly_file.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\line_poly_file.cpp(8) : error C2377: 'GLsizei' : redefinition; typedef cannot be overloaded with any other symbol
1> C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\GL/gl.h(49) : see declaration of 'GLsizei'
1>.\line_poly_file.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\line_poly_file.cpp(9) : error C2146: syntax error : missing ';' before identifier 'ww'
1>.\line_poly_file.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\line_poly_file.cpp(9) : error C2086: 'int GLsizei' : redefinition
1> .\line_poly_file.cpp(8) : see declaration of 'GLsizei'
1>.\line_poly_file.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Build log was saved at "file://c:\Documents and Settings\faiza\My Documents\Visual Studio 2005\Projects\line_poly_file\line_poly_file\Debug\BuildLog.htm"
1>line_poly_file - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Hmm solved one of my silly mistake terminater is missing .B Happy THANKU SO MUCH to all.

This article has been dead for over six months. Start a new discussion instead.