简体   繁体   English

“无法在Visual Studio 2008 Express Edition中打开包含文件:'fstream.h'”错误

[英]“Cannot open include file: 'fstream.h'” error in Visual Studio 2008 Express Edition

When compiling this code I get: 编译此代码时,我得到:

fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory 致命错误C1083:无法打开包含文件:'fstream.h':没有这样的文件或目录

Why? 为什么?

Code: 码:

#include <windows.h>   // use as needed for your system

#include <gl/Gl.h>
#include <gl/glut.h>
#include <iostream>
#include <fstream.h>

//**************Global Data
char ifileName[30],oFileName[30];
fstream inFile,outFile;

//************ Data structure 
struct GLfloatPoint
{ GLfloat x,y;
};

const int MAX = 100;
class GLfloatPointArray
{
public:
  int num;
  GLfloatPoint pt[MAX];
};

//***************** subprograms
typedef GLfloat colorType[3];
// subprogram used to draw the control points separately
void drawDot (GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b)
{ glColor3f(r,g,b);
  glBegin (GL_POINTS);
      glVertex2f (x,y);
  glEnd();
}
// Drawing subprogram - this will draw the curve from a set of points
void drawFloatPolyLine (GLfloatPointArray P, colorType c)
{ glColor3fv (c);
  glBegin(GL_LINE_STRIP);
   for (int i=0; i < P.num; i++)
     glVertex2f (P.pt[i].x,P.pt[i].y);
  glEnd();
}

//******************** myInit 
 void myInit(void)
 {
    glClearColor(1.0,1.0,1.0,0.0);  // set white background color
    glColor3f (0.0f,0.0f,0.0f);    //default color
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
    gluOrtho2D(0.0, 640.0, 0.0, 480.0);
    // get data files
    cout << "Enter the input file name: ";
    cin >> ifileName;
    inFile.open (ifileName,ios::in);
    if (inFile.fail())
      return;
    // if want to see points for debugging add output
    // cout << "Enter the output file name: ";
    // cin >> oFileName;
    // outFile.open (oFileName,ios::out);
    // if (outFile.fail())
    //   return;
}

//***************** BEZIER Curve subprograms
// Read the control points 
void readControlPoints (GLfloatPointArray &P)
{
  inFile >> P.num;
  for (int j = 0; j < P.num; j++)
    inFile >> P.pt[j].x >> P.pt[j].y;
}
// output control points to a text file - if you want to see the 
// computations
void printPointArray (GLfloatPointArray P)
{
  outFile << "Size: " << P.num << endl << "Points:" << endl;
  for (int j = 0; j < P.num; j++)
    outFile << "(" << P.pt[j].x << "," << P.pt[j].y << ")" << endl;
}

const int MAXCONTPTS = 100;
int c[MAXCONTPTS];   // the binomial coefficients
//helper routines - compute the coefficient
void ComputeCoeff (int n)
{ int j,k;
  for (k=0;k<=n;k++)
  { //compute n! / (k!*(n-k)!)
    c[k] = 1;
    for (j = n;j>=k+1;j--)
      c[k] *=j;
    for (j = n-k;j>=2;j--)
      c[k] /= j;
  }
}
// compute the blending value
float BlendingValue (int n, int k, float t)
{ int j;
  float bv;
  // compute  c[k]*t^k * (1-t)^(n-k)
  bv = c[k];
  for (j=1; j<=k;j++)
    bv *= t;
  for (j = 1;j<=n-k;j++)
    bv *= (1-t);
  return bv;
}

// compute one point on the Bezier curve - fixed value of t
void ComputePoint (float t, int n, GLfloatPoint & p, 
                   GLfloatPointArray ctrlPts)
{ int k;
  float b;
  p.x = 0.0;
  p.y = 0.0;
  for (k = 0; k<=n;k++)
  {  b = BlendingValue (n,k,t);
     p.x += ctrlPts.pt[k].x*b;
     p.y  += ctrlPts.pt[k].y*b;
  }
}
// compute the array of Bezier points - drawing done separately
void Bezier ( GLfloatPointArray controlPts, int numInter, 
              GLfloatPointArray & curve)
{ // there are numContPts+1 control points and numInter t values to evaluate the curve
  int k;
  float t;
  ComputeCoeff (controlPts.num-1);
  curve.num = numInter+1;
  for (k=0; k<=numInter; k++)
  { t = (float) k / (float) numInter;
    ComputePoint (t, controlPts.num-1,curve.pt[k],controlPts);
  }
}

//************************ myDisplay 
void myDisplay(void)
{  
   int numbCurves;
   GLfloatPointArray ControlPts,BezCurve;
   colorType C = {0.0f,1.0f,0.0f};

   glClear(GL_COLOR_BUFFER_BIT);     // clear the screen 

   inFile >> numbCurves;
   for (int i = 0; i < numbCurves; i++)
   { 
     // read control points and draw them in red big points
     readControlPoints (ControlPts);
     glPointSize (4.0);
     for (int j = 0; j < ControlPts.num; j++)
       drawDot (ControlPts.pt[j].x,ControlPts.pt[j].y,1,0,0);
     glPointSize (1.0);
     // Compute the Bezier curve points and draw
     Bezier (ControlPts,50,BezCurve);
       // draw the Bezier curve
     drawFloatPolyLine (BezCurve,C);
     glFlush ();
   }
}

//**************************** main
void main(int argc, char** argv)
{
    glutInit(&argc, argv);          // initialize the toolkit
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
    glutInitWindowSize(640,480);     // set window size
    glutInitWindowPosition(100, 150); // set window position on screen
    glutCreateWindow("Bezier Curve drawing"); // open the screen window
    glutDisplayFunc(myDisplay);     // register redraw function
    myInit();                   
    glutMainLoop();              // go into a perpetual loop
}

The standard header is called <fstream> . 标准头称为<fstream>

Edit : Since the headers were renamed without the .h extension, all symbols were moved to the std:: namespace. 编辑 :由于标题是在没有.h扩展名的情况下重命名的,因此所有符号都被移动到std:: namespace。 You might want to add a using namespace std; 您可能想要添加using namespace std; directive or qualify cin , cout and fstream in your code. 在您的代码中指令或限定cincoutfstream

#include <fstream>

省略“.h”

before the C++ standard library 在C ++标准库之前

both iostream and fstream were in a header file: iostream和fstream都在头文件中:

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>

In Visual Studio 2002.net these headers were marked as depreciated, but still present and functional. 在Visual Studio 2002.net中,这些标题被标记为折旧,但仍然存在且功能正常。 In Visual Studio 2003.net they were removed, completely. 在Visual Studio 2003.net中,它们被完全删除了。

http://msdn.microsoft.com/en-us/library/8h8eh904(v=vs.90).aspx http://msdn.microsoft.com/en-us/library/8h8eh904(v=vs.90).aspx

省略.h并使用“using namespace std;”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误 C1083:无法打开包含文件:&#39;fstream.h&#39;:没有这样的文件或目录 - fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory 包含 fstream.h 时出错 header - error on include the fstream.h header Visual Studio 2010 Express Edition 中出现“无法打开包含文件:‘ofstream’”错误? - "Cannot open include file: 'ofstream'" error in Visual Studio 2010 Express Edition? Clion 中未找到致命错误“fstream.h”文件? - the fatal error "fstream.h" file not found happen in Clion? 无法在Visual Studio 2010中打开包含文件&#39;stdlib.h&#39; - Cannot open include file 'stdlib.h' in Visual Studio 2010 无法打开包含文件:'stdio.h' - Visual Studio Community 2017 - C++ 错误 - Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error 错误:无法打开源文件#include <libcec/cec.h> 在Visual Studio 2012中 - Error: cannot open source file #include<libcec/cec.h> in visual studio 2012 在KMDF驱动程序中包含fstream.h之后的链接器错误 - Linker error after including fstream.h in KMDF driver Visual Studio 2008 速成版调试 - Visual Studio 2008 Express Edition Debugging Visual Studio 2013:致命错误C1083:无法打开包含文件:&#39;winsock2.h&#39;:没有此类文件或目录 - Visual Studio 2013: fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM