vc里面读文件

文本文件的内容如下
NUMPOLLIES 36

// Floor 1
-3.0  0.0 -3.0 0.0 6.0



读取方式如下:


void readstr(FILE *f,char *string)
{
do
{
fgets(string, 255, f);
} while ((string[0] == '/') || (string[0] == '\n')); //空的那一行不会被读出,// Floor 1 因为加了/ 也不会被读出
return;
}

float x, y, z, u, v;
int numtriangles;
FILE *filein;
char oneline[255];
filein = fopen("data/world.txt", "rt"); // File To Load World Data From

readstr(filein,oneline);
sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles);//sscanf()经常用来分解字符串,功能非常强大


readstr(filein,oneline);

sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v); fclose(filein);