Run C++ Code Online? - c++

Is there a website I can go to to run C++ code online? I have seen a few compilers, but is there one that can also receive input from cin? I want one that can basically host a C++ .exe online, and even more preferable is if it is like the VC++ platform.

You may want to give rextester a try. Currently g++ 4.7.2 with boost libraries and ability to supply compiler args.
Edit
Visual C++ is also supported now.

http://ideone.com/ Can compile several languages, and supports stdin

Yes, Ideone can do that. It's possible to specify stdin there.

Edit: Microsoft's online compiler seems to no longer be active :(
Microsoft research have made an online version of Visual C++ here: http://webcompiler.cloudapp.net/.
It (currently?) only compiles the code and does not run it so you won't be able to check cin though :(
Running code is now supported.

Currently the best online tools seem to be
Special Online Compilers
https://cppinsights.io shows, how C++ introduces conversions, etc. and interprets the source code (current clang based)
https://godbolt.org compare C++ compilers, show disassembly, run (many current compilers including Microsoft VCC and embedded compilers)
http://quick-bench.com create and compare benchmarks (current g++ and clang)
https://www.onlinegdb.com, includes gdb debugger (g++ 7.4.0)
Online Compilers that let you set compile flags
https://wandbox.org (current g++ and clang)
http://coliru.stacked-crooked.com (g++ 9.2.0)
https://repl.it/languages/cpp11 (clang 7.0.0)
https://www.tutorialspoint.com/compile_cpp11_online.php = codingground (g++ 7.1.1)
https://tio.run/#cpp-clang (g++ 8.3.1 and clang 7.0.1)
https://rextester.com/l/cpp_online_compiler_gcc (g++ 7.4.0, clang 6.0.0, VS C++ 2015 Update 1)
Online Compilers that do not let you set compile flags
https://www.jdoodle.com (g++ 9.2.0)
https://www.codechef.com/ide (g++ 9.1.0)
https://ideone.com (g++ 8.3.0 and clang 8.0.0)
https://paiza.io (clang 8.0.0)
https://www.codiva.io/c (clang 7.1.0)
https://code.labstack.com/cpp (g++ 8.3.0)
All listed compilers support C++17 code

Perhaps the following site is what you're aiming for: http://codepad.org/

There is Wandbox.org, which offers GCC and Clang to its latest versions (as of Nov 2018). It has stdin.
I wouldn't say it's a VC++ platform though.

TutorialsPoint's C++ Coding Ground lets you save and compile multiple source files at a time, which can be useful at times, and gives you a GNU bash console to play around with. It's not as convenient for sharing code as sites like Ideone, however.
[Note: While it only has links to C++, C++0x, and C++11 environments, you can compile code for C++14 by specifying the compiler option -std=c++1y. I'm not sure if it has any experimental C++17 support, however.]

repl.it can compile, run, and execute C++ and C++11. It's also interactive and you can ask for user input in realtime.

Related

Do any compilers currently support C++20?

I purchased a book recently entitled beginning C++20. I was looking to begin learning c++ though I now realize that I can't find a compiler that can run the code in the book as I get an error since the compiler I'm using (xcode) does not support c++ 20. I'm wondering if there are any compilers that I can run on my mac that support c++20.
gcc version 8 and up supports some of C++20; you can try using that.
It should also be noted that Xcode isn't a compiler, but instead an IDE that should be using clang as the actual compiler. Clang also currently has support for some of the C++ 20 features. To use them the -std=c++20 flag will still be needed.
Here can you find the currently implemented feature support of the GCC compiler of the C++20 specification:
GCC Link
But you need to enable it in your console command or add this to your toolchain: "-std=c++20"

Clang built on GCC

I was searching online to see if clang supported reproducible builds. I read that GCC guaranteed reproducible builds using the -frandom-seed flag. I wanted to know if clang supports that flag and I could not find anything regarding that.I then came here which had a statement such as:
...two consecutive builds of (GCC-built) Clang
My question is what is GCC built clang ? I am currently aware of only 2 compilers (Microsoft , GCC (Coudl be Cygwin/Mingw flavor) ) and the third one was suppose to be clang. My question is what does clang (GCC built) mean ? Built from source ? I would like to think that clang is a totally different compiler from GCC and Windows. Also this documentation here states
Clang has experimental support for targeting “Cygming” (Cygwin /
MinGW) platforms.
What does that mean ? Does clang mean that it uses Mingw GCC as a compiler ? What does targeting mean here ?
To my mind, this phrase means clang was built from source using GCC as a compiler. Then, clang is a compiler, so it can't use GCC as a compiler.
Compilers are written in programming languages to be able to compile code written in a programming language. This means, a compiler can compile a compiler or even itself.
If you don't know is feature X supported in product Y, please, read the docs on product Y. If this feature isn't mentioned, it's not supported and vice versa.

what c++ norme i'm currently using? [duplicate]

This question already has answers here:
How to determine the version of the C++ standard used by the compiler?
(9 answers)
Closed 6 years ago.
Recently I had faced compiling errors in a c++ code I wrote so I've been asked if I was using a C++11 compiler, but honestly I don't know how to check on my compiler version ! so any idea how to figure this out ??
Btw I'm using codeblocks as an IDE which includes the GCC compiler and GDB debugger from MinGW. also if I'm compiling my c++ code under Linux what command should I run to know my compiler version ?
That can be a tricky question. C++11 refers to a version of the
standard, not to a version of the compiler. Different compilers, and
different versions of any given compiler, will typically implement a mix
of versions of the standard, at least for recent versions. More or
less, because any implementation of C++11 will be fairly new, and thus
probably fairly buggy.
Most compilers have options to output the version; many will output it
systematically in verbose mode. For g++, try g++ --version. Recent
versions of g++ do have some support for C++11, but you have to activate
it with -std=c++0x (rather than the usual -std=c++03 or
-std=c++98). As the name (c++0x, rather than c++11) indicates, it
is not truly C++11; it is an implementation of some (most?) of the
major new features, in a preliminary version based on various working
papers, and not the final standard.
(FWIW: I don't think any compiler fully implements all of C++11, but I'd
love to be proven wrong.)
You can find out your compiler version like this:
g++ --version
That doesn't tell you if you are using c++11. To use c++11 features, you would have to call the compiler with thr -std=c++0x flag:
g++ -std=c++0x ....
Bear in mind that gcc doesn't implement 100% of c++11 yet, and how much it implements depends on the version. See here for a table of supported features.
EDIT: strictly speaking, if you are using GCC you cannot be using a fully compliant c++11 compiler due to the missing features. But versions 4.6.1 onwards cover a great deal of the standard.
If you're in linux, checking the version is easy.
> gcc --version
Will tell you the version you have. Note that GCC C++11 support is incomplete still, you can find the details here: http://gcc.gnu.org/projects/cxx0x.html
I've used a few C++11 features myself, namely initializer lists, and the nullptr constant. I'm using GCC 4.6 and it's working fine.
edit: And yes, as #jaunchopanza said, you'll need the -std=c++0x compiler flag to make it work. If you're using Code::Blocks, just right-click on your project, choose Build options..., and check the item that says Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]

C++11 compiler for windows

I was just watching a few videos on Channel9. I found things like lambdas really cool. when I tried to copy the example, it failed. auto didn't work either.
I'm using Nokia's qtcreator which ships with gcc-4.4.0.
I wanted to know which compiler has the fun features implemented so I could play around and learn. I'm not anti MS or anyhting so I don't mind trying Visual Studio if it has those features.
Nearly all C++11 features are implemented in the GCC 4.6.x . A good place to get latest GCC builds (MinGW) is the TDM website - http://tdm-gcc.tdragon.net/download . It should be easy to replace your current GCC with TDM GCC by overwriting files...
A special version of MinGW:
MinGW-Builds gives you everything gcc offers (currently 4.7.2)
That is: Including support for std::thread, std::async, std::future and friends.
As far as I know that's by far the most complete C++11 you can get on Windows.
You just get the MinGW-build binaries here. Unlike other gcc-based installations it supports posix threads, which are currently key to getting the gcc support for C++11 threads and friends working on Windows.
Extract the directory mingw to any location and add the following two paths to your PATH environment variable: (well, change F:\coding ...)
F:\coding\MinGW\bin
F:\coding\MinGW\msys\1.0\bin
Add both, separated by semi colon. You will need to log out or reboot. To verify that you got it right, you can open a command prompt, and write
g++ --version
You should get a response like this, mentioning MinGW-builds:
g++ (Built by MinGW-builds project) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc. ...
I wrote a more complete instruction for getting this going with Eclipse, here: http://scrupulousabstractions.tumblr.com/post/36441490955/eclipse-mingw-builds
For playing around and learning C++11 on Windows, I recommend MinGW Distro by Stephan T. Lavavej. The newest version contains GCC 4.8.2 and Boost 1.55.0.
Take a look at MinGW-w64 if you're looking for a gcc-compatible compiler on Windows that supports a number of C++11 features.
Also if you're just looking for lambas and auto, as well as some other C++11 features like decltype, etc., (again, not as many feature are implemented compared to the latest stable gcc branch) then you can also use the free Visual Studio 2010 Express for C++ on Windows.
See here for an overview of the compilers and the supported C++11 features.
Scott Meyers maintains a webpage here:
C++11FeatureAvailability
The First link on the Webpage is:
Apache Wiki Overview of C++11 Support in Several Compilers is what you should have a look at.It doccuments in detail C++11 features supported by all popular compilers.
The Visual Studio 11 preview also supports lambdas.
Visual Studio 2017 has support in C++11, C++14, & C++17. + some of the Modern C++ "experimental" modules. If you decide on Visual Studio, you set the C++ standard at the project properties. C++11 is by default, but you can set it to C++14, C++17, or latest draft.
As regards g++, C++0x feature support should be detailed here: C++0x/C++11 Support in GCC - GNU Project - Free Software Foundation (FSF)
If you want to test most of the C++11 syntax using a Windows machine you have two options:
Install Cygwin and compile from sources gcc-4.7 (latest snapshot) and clang++ with libstdc++. However it is not guaranteed that this will work.
Safest bet: Install a modern Linux (such as Ubuntu if you are a Linux newbie) in a virtual machine (VirtualBox is a free virtual machine application) and in this virtual machine compile gcc-4.7 and clang++. I was able to successfully compile both of them on Ubuntu 11.10 following the instructions from this website.
Best option, as of 2014, is to use Visual Studio 2013 updated with the latest CTP (this will work even for the Express edition).
Few Min-GW Compilers do not support C++ Version 11 or later. This version is required for thread in OpenCV. So I will suggest using TDM-GCC Compiler instead of MinGW Compiler. Install this compiler and set path C:\TDM-GCC-64\bin to the system's environmental variable.

Reducing the execution time of the code using CLANG/LLVM compiler

Well... When i was searching for a good compiler I came across clang/LLVM. This compiler gives me same result as other compilers like icc, pgi. But the problem is there are very few tutorials on this compiler... Kindly let me know where can I find the tutorials on the clang compiler.
Note by:
I have compiled my c code using the following flags clang -O3 -mfpmath=sse file.c
Clang (the command line compiler) takes gcc-compatible options, but accepts and ignores a lot of flags that GCC takes (like -mfpmath=sse). We aim to generate good code out of the box. There are some flags that allow clang to violate the language standards that can be useful in some scenarios, like -ffast-math though.
If you're looking for good performance, I highly recommend experimenting with link-time-optimization, which allows clang to optimize across source files in your application. Depending on what platform you're on, this is enabled by passing -O4 to the compiler. If you're on linux, you need to use the "gold" linker (see http://llvm.org/docs/GoldPlugin.html). If you're on the mac, it should "just work" with any recent version of Xcode.
The clang is not a compiler, it is just frontend of LLVM compiler. So, when you calls clang, it parses c/c++ file but the optimization and code generation is handled in LLVM itself.
Here you can found a documentation of LLVM optimization and analysis options: http://llvm.org/docs/Passes.html
The full documentation is here http://llvm.org/docs/
Also useful options are listed here http://linux.die.net/man/1/llvmc (I suggest clang will accept most of them too)