本文整理汇总了C++中FILE::good方法的典型用法代码示例。如果您正苦于以下问题:C++ FILE::good方法的具体用法?C++ FILE::good怎么用?C++ FILE::good使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FILE
的用法示例。
在下文中一共展示了FILE::good方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseObjFile
void parseObjFile(const char* objPath,
std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& texcoords,
std::vector<glm::vec3>& normals, std::vector<GLuint>& vertIndices,
std::vector<GLuint>& texIndices, std::vector<GLuint>& normIndices) {
#if (defined USE_FSCANF || defined USE_FGETS)
GLchar buf[BUFSIZE];
FILE* fp;
// in Win/VS2010, position from ftell after fopen in text mode
// is not accurate (due to translation of newlines)
if ((NULL == objPath) || (NULL == (fp = fopen(objPath, "rb")))) {
return;
}
#ifdef USE_FSCANF
while (EOF != fscanf(fp, "%s", buf)) {
#else // USE_FGETS
while (NULL != fgets(buf, sizeof(buf), fp)) {
#endif
#else // USE_GETLINE
GLchar* buf;
std::string str;
std::ifstream fp(objPath);
if (!fp.is_open()) {
return;
}
while (fp.good()) {
std::getline(fp, str);
#endif
GLint res = 0;
#ifdef USE_GETLINE
buf = (GLchar*)str.c_str();
#endif
switch (buf[0]) {
case 'v':
#if (defined USE_FGETS || defined USE_GETLINE)
if (' ' == buf[1]) {
#else // USE_FSCANF
if (1 == strlen(buf)) {
#endif
glm::vec3 vert;
#if (defined USE_FGETS || defined USE_GETLINE)
res = sscanf(buf, "v %f %f %f",
#else // USE_FSCANF
res = fscanf(fp, "%f %f %f\n",
#endif
&vert.x, &vert.y, &vert.z);
if (DIM3 != res) {
fprintf(stderr, "Incorrect vert matches on sscanf\n");
}
vertices.push_back(vert);
} else if ('t' == buf[1]) {
glm::vec2 tex;
#if (defined USE_FGETS || defined USE_GETLINE)
res = sscanf(buf, "vt %f %f",
#else // USE_FSCANF
res = fscanf(fp, "%f %f\n",
#endif
&tex.x, &tex.y);
if (DIM2 != res) {
fprintf(stderr, "Incorrect tex matches on sscanf\n");
}
texcoords.push_back(tex);
} else if ('n' == buf[1]) {
glm::vec3 norm;
#if (defined USE_FGETS || defined USE_GETLINE)
res = sscanf(buf, "vn %f %f %f",
#else // USE_FSCANF
res = fscanf(fp, "%f %f %f\n",
#endif
&norm.x, &norm.y, &norm.z);
if (DIM3 != res) {
fprintf(stderr, "Incorrect norm matches on sscanf\n");
}
normals.push_back(norm);
}
break;
case 'f':
GLuint vertsIdx[VERTS_FACE], normsIdx[VERTS_FACE],
texIdx[VERTS_FACE] = { 1, 1, 1 };
#if (defined USE_FGETS || defined USE_GETLINE)
res = sscanf(buf, "f %d/%d/%d %d/%d/%d %d/%d/%d",
#else // USE_FSCANF
// ensure fopen with binary NOT text mode for Win/VS2010
long posPtr = ftell(fp); // get current stream pos
res = fscanf(fp, "%d/%d/%d %d/%d/%d %d/%d/%d\n",
#endif
&vertsIdx[0], &texIdx[0], &normsIdx[0],
&vertsIdx[1], &texIdx[1], &normsIdx[1],
&vertsIdx[2], &texIdx[2], &normsIdx[2]);
if (RES_VertTexNorm != res) {
#if (defined USE_FGETS || defined USE_GETLINE)
res = sscanf(buf, "f %d//%d %d//%d %d//%d",
#else // USE_FSCANF
fseek(fp, posPtr, SEEK_SET); // reset stream pos
res = fscanf(fp, "%d//%d %d//%d %d//%d\n",
#endif
//.........这里部分代码省略.........