<iostream> error in gcc and g++

I have the code below. I have tried compiling with gcc and g++ to no avail. For gcc it gives a fatal iostream error. For g++ it throws a huge list of errors. I'm fairly new to programming, and have no idea how to get this to compile. I'm very lost.

Here is the code:

using namespace std;
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <math.h>
#if defined(__sparc)
#include <ieeefp.h> // include file for "finite" function on sparc
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "surfstruct.h"
#include "surf3dread.h"
/* #include "caretio.h" */
#include "flags.h"
#include "read.h"
#include "error.h"


/* Global Variables */
extern int nvertex, ntriangle, offset;
extern int tri_notsurf, triangle_ttl, vertex_ttl, u_edge_insurf_ttl;
extern int **colour_int, **tricolour_int;
extern float **colour_flt;
extern int GEOG, surftype;
extern struct vertexinfo *vertex;
extern struct triinfo *triangle;
extern struct edgeinfo *edge;
extern int TriNumCmp(const void *, const void *);

//int ReadByuSurf(FILE *infile, FILE *outfile , char *name) {
int ReadByuSurf(FILE *infile, fstream &outfile , char *name) {
char header[length];
int t, v, tmp, nedge;

offset = 1; /* vertex offset */
printf("Vertex and triangle offset = %d\n",offset);
// fprintf(outfile,"Vertex and triangle offset = %d\n",offset);
outfile << "Vertex and triangle offset = " << offset << endl;

/* check the input file exists */
printf("Reading 3d co-ordinates in file %s ...\n",name);
// fprintf(outfile,"Reading 3d co-ordinates in file %s ...\n",name);
outfile << "Reading 3d co-ordinates in file " << name << " ..." << endl;

/* read input file to get vertices and metric info */
GetLine(infile, header);
sscanf(header, "%d %d %d %d", &tmp, &nvertex, &ntriangle, &nedge);

/* unused input line */
GetLine(infile, header);

// fprintf(outfile, "%7d vertices (given)\n", nvertex);
outfile << nvertex << " vertices (given)" << endl;
printf(" %d vertices to process\n",nvertex);
vertex = (struct vertexinfo *) calloc(nvertex, sizeof(struct vertexinfo));
if (vertex==NULL) {
char *str = "vertex structure";
Error(97,str);
}

for (v = 0; v < nvertex; v++) {
vertex[v].contour = -1;
if (fscanf(infile, "%f %f %f", &vertex[v].coord3d[X], &vertex[v].coord3d[Y], &vertex[v].coord3d[Z]) < 3) {
char str[length];
sprintf(str,"vertex %d in file %s",v+offset,name);
Error(95,str);
} else GEOG = FALSE;
if (v==0 || v==nvertex-1) {
// fprintf(outfile," ... processing vertex %d: x y z = %f %f %f\n",v+offset, vertex[v].coord3d[X], vertex[v].coord3d[Y], vertex[v].coord3d[Z]);
outfile << " ... processing vertex " << v+offset << ": x y z = " << vertex[v].coord3d[X] << " " << vertex[v].coord3d[Y] << " " << vertex[v].coord3d[Z] << endl;
printf(" ... processing vertex %d: x y z = %f %f %f\n",v+offset, vertex[v].coord3d[X], vertex[v].coord3d[Y], vertex[v].coord3d[Z]);
}
}

printf("Reading triangles in file %s ...\n",name);
// fprintf(outfile,"Reading triangles in file %s ...\n",name);
outfile << "Reading triangles in file " << name << " ..." << endl;
printf(" %d triangles to process\n",ntriangle);
// fprintf(outfile, "%7d triangles (given)\n", ntriangle);
outfile << ntriangle << " triangles (given)" << endl;
triangle = (struct triinfo *)calloc(ntriangle,sizeof(struct triinfo));
if (triangle == NULL) {
char *str = "triangle structure";
Error(97,str);
}

/* read in triangles */
for (t = 0; t < ntriangle; t++) {
if (fscanf(infile, "%d %d %d", &triangle[t].vertex[0], &triangle[t].vertex[1], &triangle[t].vertex[2]) < 3) {
char str[length];
sprintf(str,"triangle %d in file %s",t+offset,name);
Error(95,str);
}
GetLine(infile, header); /* read remaining part of line */
triangle[t].vertex[0] -= offset;
triangle[t].vertex[1] -= offset;
triangle[t].vertex[2] = ((-1)*triangle[t].vertex[2])-offset;
if (t==0 || t==ntriangle-1) {
// fprintf(outfile," ... reading triangle %d with vertices: %d %d %d\n",t+offset,triangle[t].vertex[0]+offset,triangle[t].vertex[1]+offset,triangle[t].vertex[2]+offset);
outfile << " ... reading triangle " << t+offset << " with vertices: " << triangle[t].vertex[0]+offset << " " << triangle[t].vertex[1]+offset << " "
<< triangle[t].vertex[2]+offset << endl;
printf(" ... reading triangle %d with vertices: %d %d %d\n",t+offset,triangle[t].vertex[0]+offset,triangle[t].vertex[1]+offset,triangle[t].vertex[2]+offset);
}
}
if (fscanf(infile, "%d", &v) !=EOF) Error(90,name);
return(0);
} /* end ReadByuSurf */
Last edited on
The gcc is a C-compiler. It does not understand C++ standard library.

The g++ error message. What is the first error? On which line of code? (The message does list line-number.)


This site has code tags. Put your code within those tags. That makes code more readable.

Your code does mix I/O-features of both C++ and C. That is not good.
Always start with the first error in the list. Often one error will make the compiler report other errors later in the code which makes it look like there are more errors than actually is the case.
Topic archived. No new replies allowed.