how to test C or C++ snippet quickly?
I am using Ubuntu and Eclipse as an IDE for C/C++.
I currently have a big project in Eclipse. Sometimes, I want to test some small functions written in C/C++ but I don't want to re-create a new project in Eclipse. It is much time consuming and slow. I want to ask if there is any better way to do this ?
(In the past, I usually used a combination of GEDIT and GCC from the shell, but I really like the auto-completion or intellisense feature in Eclipse, which GEDIT does no开发者_StackOverflow社区t have. I have also tried Scribes but it does not have a full intellisense feature like Eclipse)
Use online compiler like Ideone or Codepad.
Ofcourse, they dont provide you auto code completion feature & other fancy features but that is the price you pay for quick & easy way of checking stand alone functions.
This method works without an internet connection and without exposing your code.
<ctrl>+<alt>+T <-- 0) opens a terminal
vi test.cc <-- 1) hackery
...
g++ -Wall -Wextra test.cc && ./a.out <-- 2) compile + run
rm test.cc <-- 3) clean up (optional)
Replace vi
with your favourite editor or cat
. Can't be less obtrusive.
Some editors like SciTE have some very basic code completion (btw btw: SciTE has shortcuts to directly compile and run code from within the editor).
Btw: QtCreator gives some decent "intellisense", and the project files are minimal. A single project file line is enough for such one-function-test.
unkulunkulu points out that you can also replace step 2 like this (there should better be no Makefile
in your try-out folder; could conflict with existing targets in that):
<ctrl>+<alt>+T <-- 0) opens a terminal
vi test.cc <-- 1) hackery
...
make test && test <-- 2) compile + run
rm test.cc <-- 3) clean up (optional)
It has the tiny disadvantage that telling g++ about extra arguments (like -Wall
or -std=c++0x
is a bit more obtrusive).
I will advise you to use gedit with the embeded terminal plugin.It allows quick compiling through the embeded terminal.Perfect for quick testing.
You can use tcc as a C script engine.
$ cat tcctest.c
#!/usr/bin/tcc -run #include <stdio.h> int main(void) { printf("Hello, tcc!\n"); return 0; }
$ chmod u+x tcctest.c
$ ./tcctest.c
Hello, tcc!
http://www.compileonline.com I found this Site more useful than ideone or codepad because it supports more languages than codepad and you can see the output of you code on an adjacent window you can also provide Standard Inputs and command line arguments and you can also access a file input.txt in your program.
精彩评论