Preprocessor directives Help!

03/21/2015 15:29 elmarcia#1
Hi guys i'm trying to code a handle to a file so that i can write to it, i'm a bit confused cause i don't know if i can make it work that way.

First i tried this way:

It won't compile anyway..

Then i try to process everything together like this:

Will compile but, will make stack error and won't create the file :C

So, if i use the first example and remove the #if and replace it in the main function will work, but i'll have to declare a FILE* handle, and that crap and i don't want to do it...

Is it posible to make it work in preprocessing section or not??

:handsdown::handsdown:
03/21/2015 17:51 warfley#2
Well this doesn't make any sense either, the Preprocessor works before the Real Compilation, so Checking if a file exists while Compiling 1. Doesn't make any sense, because lets say that the program is compiled, than you got a handle as a constant in your program. Even if you change your file, or restart your pc, it will have the same handle, it just can't work
2. It doesn't work, because preprocessing is done before the Compilation, using C++ code in this statements just can't work well because the preprocessor doesnt work with C++ commands.


here a little example, try this little program:
Code:
#include <iostream>

#define FILENAME "/data.dat"
#define EXIST (fopen(FILENAME,"r") == NULL)?"true":"false"  //Exist or not

int main()
{
  std::cout << EXIST;

  return 0;
}
the result is 1%
03/21/2015 18:16 elmarcia#3
Thx dude, i really messed up with that haha. I will continue reading about that before doing such things like these... :c

#closerequest
03/21/2015 18:57 snow#4
#closed (on request)