Imnotanerd
Imnotanerd

Reputation: 1167

C++ File IO - can't find methods for File IO related stuff

#include "Shader.h"
#include <cstring>
#include <iostream>
#include <cstdlib>
using namespace std;

static char* textFileRead(const char *fileName) 
{
    char* text;

    if (fileName != NULL) 
    {
        FILE *file = fopen(fileName, "rt");

        if (file != NULL) 
        {
              fseek(file, 0, SEEK_END);
              int count = ftell(file);
              rewind(file);

            if (count > 0) 
            {
                text = (char*)malloc(sizeof(char) * (count + 1));
                count = fread(text, sizeof(char), count, file);
                text[count] = '\0';
            }
            fclose(file);
        }
    }
    return text;
}

This is what I have for a shader program found in a tutorial I'm trying to follow. When I build this to check for errors, I get errors saying fopen(), fseek(), ftell(), rewind(), and fclose() isn't declared in this scope. How can I get rid of these errors?

Upvotes: 0

Views: 208

Answers (2)

Aater Suleman
Aater Suleman

Reputation: 2328

You need add the header file for standard IO as follows:

#include <stdio.h>

or (c++ preferred)

#include <cstdio>

Upvotes: 2

Ed Manet
Ed Manet

Reputation: 3178

You're using C file IO in a C++ program. You included iostream.h, so use it.

http://www.cplusplus.com/reference/iostream/

Upvotes: 2

Related Questions