Zhani Baramidze
Zhani Baramidze

Reputation: 1497

Sublime C++ define from settings

I'm using sublime editor and want such things for programming competitions (TopCoder): when testing locally, I want to read from file, but when sending, I want code to read from console. Now, I do it like this: I have 2 lines:

freopen("A.in", "r", stdin);
freopen("A.out", "w", stdout);

which I comment prior sending. Is there anything like define something from IDE, and then used #ifdef to decide if I'm compiling locally or sending?

Upvotes: 0

Views: 899

Answers (1)

Ferruccio
Ferruccio

Reputation: 100668

Make up your own symbol. e.g.

#ifdef JANI_LOCAL
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

When you compile it locally define the symbol on the command line (assuming g++ compiler):

g++ -DJANI_LOCAL source.cpp

The code between the #ifdef/#endif will be compiled locally but will be ignored when compiled by the judging software.

Upvotes: 2

Related Questions