What is the correct way to declare and use a FILE * pointer in C/C++? Should it be declared global or local? Can somebody show a good example?
C++ – the correct way to declare and use a FILE * pointer in C/C++
cfile
Related Topic
- C++ – a smart pointer and when should I use one
- C++ – What does the explicit keyword mean
- C++ – The Definitive C++ Book Guide and List
- C++ – the difference between const int*, const int * const, and int const *
- C++ – the “–>” operator in C/C++
- C++ – The Rule of Three
- C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming
- C++ – use a pointer rather than the object itself
Best Answer
It doesn't matter at all whether it's local or global. The scope of the file pointer has nothing to do with its use.
In general, it's a good idea to avoid global variables as much as possible.
Here's a sample showing how to copy from
input.txt
tooutput.txt
: