FILE in CPP

I have some C code which opens a file in the TEMP directory, writes to it and closes it.

1
2
3
4
5
6
7
8
FILE* fp;
char buff[1024];
const char* env_p = getenv("TEMP");
strcpy(buff, env_p);
strcat(buff, "\\somefilename.dat");
fp = fopen(buff, "w");
fprintf(fp, "%s\n","some text");
fclose(fp);


Now I need to call a C++ function from the above code which also writes some text into this file.

C++ function:
1
2
3
4
extern "C" void othertext(FILE* fp)
{
    fprintf(fp, "%s\n","C++ stuff");
}

The C++ code won't compile as it does not know what FILE is. Now I know C++ supports a newer file handling format with "myfile <<" etc. But I understood it stills supports the old fprintf format too.

So 2 questions:
1. If I still use the old fprintf format, how can I get the C++ to compile with the FILE* variable?
2. If I use the newer format how do I convert FILE* into ofstream ?
Last edited on
Have you included the header <cstdio>? Note that the C++ version of the headers put the names in the std namespace so you might have to write std::FILE, std::fopen, etc.
Last edited on
Thanks, including cstdio did it.
Topic archived. No new replies allowed.