tanvir_cse's blog

By tanvir_cse, history, 8 years ago, In English

this is common thing that happened to me when i solve a problem and i want to submit it then i got WA because of i forgot to comment my testing file input... Now i saw that someone use this in main

ifdef NEREVAR_PROJECT

freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

endif

but i don't understand that many people use many different thing at the position "NEREVAR_PROJECT" .. then i am trying to copy that and use but it's not work in my text editor . plz explain me what is it and what it means and what it does...and how it use... thanx in advance

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Auto comment: topic has been updated by tanvir_cse (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Auto comment: topic has been updated by tanvir_cse (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +36 Vote: I do not like it

People who prefer locally to use freopen always amaze me. This is so much less convenient than typical "./A < A1.in". To solve your problem read about compilation flags.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Works only for linux :)

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Works perfectly fine on Windows as well.

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it +13 Vote: I do not like it

        Yeah, you really using Windows console? Only if you using something like Far.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    I personally like using freopen locally, especially when debugging on some small sample. I keep adding debug prints and compiling every few seconds, so I like tapping F9 to compile&run and having the input automatically in there.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Guess it depends on, where/how you like to program.

      If you are on some IDE & similar, it -indeed- is much more comfortable to use "freopen" {imho}

      Anyway if one prefers terminal, you can do (at least in Linux) aliases (or shortcuts), which make this process faster:

      Some examples:

      alias p='g++ -Wall -pedantic -Wno-long-long -std=c++11 main.cpp;cat src.txt|./a.out'
      
      alias ca='g++ -Wall -pedantic -Wno-long-long -std=c++11 main.cpp;find *.in |xargs -I % sh -c "echo File %;./a.out < %;"'
      

      if "p" is executed in terminal, code is compiled and run with input from "src.txt"

      if "ca" is executed in terminal, code is compiled and run with input from all files, which ends with ".in"

      This might make programming faster :)

      Have nice day ^_^

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hope this can help you :)

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

ifndef ONLINE_JUDGE

///here goes your testing task during your coding time in IDE.No need to comment it when you will submit your code
#endif // ONLINE_JUDGE