← Back to topics
Topic

C++ inline submission

adminModerator
Download the "zi.h" file from here: www.z-trening.com/static/cc/zi.h

Put the file in the same directory as your solution. For example if you were solving the problem "Sum of two numbers" your solution would look like:

#include <iostream>
#include "zi.h"

int main () {
ZGRADE(admin, 5000000001);
int a, b;
std::cin >> a >> b;
std::cout << (a+b);
return 0;
}


Of course, you have to put your own username
Compile and run the code.

Linux/Win(cygwin)
#g++ sum.cc -o sum.bin
#./sum.bin

Win(MinGW)
>g++ sum.cc -lws2_32 -o sum.exe
>sum.exe


I would like to hear your opinions about this.

Dgleich
Great Idea :)
adminModerator

The instructions from the file header

/**
* HOW TO USE THIS HEADER FILE:
* - Login to www.z-training.net using your browser
* - In your solution include this file ("zi.h"). DO NOT RENAME THE FILE!
* - In your main function make the first line ZGRADE(username, taskId);
* where username is your z-training username (without quotes!) and
* taskId is the id of the task you are solving
* - Compile and RUN!
*
* The submission for the task "Sum of Two Numbers" would look like this:
*
* #include <iostream>
* #include "zi.h"
*
* int main () {
* ZGRADE(admin, 5000000001);
* int a, b;
* std::cin >> a >> b;
* std::cout << (a+b);
* return 0;
* }
*
* Linux (gcc): g++ sum.cpp -o sum.bin; ./sum.bin
* MacOS (gcc): g++ sum.cpp -o sum.bin; ./sum.bin
* Windows (cygwin): g++ sum.cpp -o sum.bin; ./sum.bin
*
* Windows (MinGW): g++ sum.cpp -lws2_32 -o sum.exe
* sum.exe
*
* Windows (Dev C++): In Tools/Compiler options check the field
* `Add these commands to the linker command line`
* and in the textbox below add "-lws2_32" (no quotes)
* press "F9" and voala!
*
* Windows (VS): Not tested, but should work out of the box.
*
*
*/
harta01
I have tested it...
What a great feature!!!
deniz
Somebody must help me with this new feature.
I'm using Dev C++ on Windows XP. I put the zi.h file in the folder where my solution is located and made the required modifications on the Compiler options.

I typed this code for the Sum of two numbers problem:


#include <iostream>
#include "zi.h"

int main ()
{
ZGRADE(deniz, 5000000001);
int a, b;
std::cin >> a >> b;
std::cout << (a+b);
system("pause");
return 0;
}


I pressed F9, the compiler printed deniz :: 5000000001, and after a second, the output screen closed, without printing anything else.

Do you know what's wrong?
harta01
@deniz: there is nothing wrong with it. If you are connected with internet and you login with your own ID, you can see your solution is wrong or no(it is graded).
adminModerator
@deniz

Find this code in "zi.h"

#define ZGRADE(_user_, _task_)                  \
do { \
std::string s; \
GETMYCONTENT(s); \
std::cout << #_user_ << " :: " \
<< #_task_ << std::endl; \
zi::postSubmission(#_user_, #_task_, s); \
return 0; \
} while(false)


and add something before return 0 that will pause the screen. You can for example read an integer:


#define ZGRADE(_user_, _task_)                  \
do { \
std::string s; \
GETMYCONTENT(s); \
std::cout << #_user_ << " :: " \
<< #_task_ << std::endl; \
zi::postSubmission(#_user_, #_task_, s); \
int x; std::cin >> x; \
return 0; \
} while(false)
deniz
thanks
dario-dsa
#include <iostream>
//#include "zi.h"

int main () {
//ZGRADE(dario-dsa, 5000000008);
int a, b;
scanf("%d",&a);
printf("%d",a);
return 0;
}

Whats wrong?
adminModerator
Now you can also do:


#include <iostream>
#include "zi.h"
ZGRADED(dario-dsa, 5000000008);

int main () {
int a, b;
scanf("%d",&a);
printf("%d",a);
return 0;
}

You can put ZGRADED anywhere in the global space (but after [[#include "zi.h"]])
iggy91
AND you need to re-download zi.h file if you haven't done so... ;)

You forgot to mention that. :D
ortschun
I always get "getaddrinfo was not declared in this scope" error.
aleksa92
If you are using Code::Blocks under MS windows you will have to install Dev-cpp, then start codeblocks, choose "global compiler options" menu, then under "search directories" tab and in "compiler" subtab add:" c:\Dev-cpp\include". Also in same menu under "Linker Settings" tab add "-lws2_32" in "Other linker options" field.
ortschun
I am using MiniGW and trying to compile it with the command that is written here.
adminModerator
Try including the MinGW include directory.

g++ -Ic:\Dev-cpp\include ...


Locate this files: "winsock2.h" and "ws2tcpip.h" and make sure you include that dir.
aleksa92
If you have troubles even after including c:\Dev-cpp\include, you will have to modify a litlle bit a ws2tcpip.h file. Just delete following lines:

297: #if (_WIN32_WINNT >= 0x0501)
303: #else
305: #endif

This worked for me, without installing Dev-cpp...
ortschun
Thanks! aleksa92's help worked for me! Awesome feature!
t
tutor
@aleksa92: Can you send me the original ws2tcpip.h you have. I can probably make some workaround, and make the zi.h work without modifying the header file.

-Thanks (ADMIN)
aleksa92
Admin, can you give me your email so i can send you file?

My email: opaki@inbox.com
adminModerator
admin@z-trening.com
CharlieAmer
can you please tell me where is written taskid ? I can't find it anywhere in tasks :(
dario-dsa
http://7291933564444255484-a-1802744773732722657-s-sites.googlegroups.com/site/dariodsahr/Home/ada.bmp?attachauth=ANoY7coZOA86lHRmuTprfp3c1xlpTHUPpacwyycxc86xMhQpZ0XHFcaIxJeGyl5wwhBQsX9B73abEJqFKiOUblUkZuq4D9YbrQkQB-ytqEgUcNlW9g92j9ISiF-5tYbcj-vV3zixhFI-UepzGdDzYNIJ0ViA201frEQfWNA1r6pOHQRcBL9bOMcjAErlOFcPuK6nzQByv68s&attredirects=0
niksa
You people are amazing :D
ZLATKO
I receive this:
"Error: Not logged in. Please login on www.z-training.net from this computer."
even though I am logged in :-|
Compiling/linking with Dev-Cpp w/o a problem.
Thanks a lot.
ZLATKO
Found it.