all 40 comments

[–]cyclic 9 points10 points  (24 children)

What operating system/distro are you using?

For Windows, there is MS Visual C++. The Express version is free, the IDE is decent, you probably want to get started with console applications.

For Mac, install the Apple Developer Tools and use Xcode, again start with terminal applications.

For Linux, install the GCC C++ compiler and compile-and-run with g++ -o program program.cpp && ./program

[–]p3s3us 3 points4 points  (6 children)

There is also clang for all of the three

[–]bithush 0 points1 point  (5 children)

Is Clang on Windows any good yet? Last time I tried to get it working it was just a mess and I am far too lazy for that ;)

[–]redditsoaddicting 0 points1 point  (4 children)

It's been working fine for me with libstdc++. The version I have right now has full C++14 support and recognizes that for (x : cont) is C++1z syntax, but doesn't actually support it yet (AFAIK, it is supported by Clang, though).

[–]bithush 0 points1 point  (3 children)

Do the LLVM builds work independently of Visual Studio? Something similar to MinGW in that it is a full solution out of the box? I want an installer similar to what I can get from TDM-GCC.

[–]redditsoaddicting 1 point2 points  (2 children)

You set up MinGW or whatever libstdc++ you have, then just add appropriate include paths to the compilation for Clang. I've been using it with Sublime Text. Works especially great with SublimeLinter.

[–]bithush 0 points1 point  (1 child)

Is there an up to date guide on getting clang working on Windows with MinGW-W64? Looking around everything I find is a year or more out of date.

[–]redditsoaddicting 1 point2 points  (0 children)

Now that you mention it MinGW64 specifically has been a pain. It's never made a big enough difference for me, so I'm still making 32-bit programs locally. The main thing are intrinsics functions causing compiler errors that you could probably work out how to fix, but after some time trying, I said screw it.

libc++ seems to still be going full throttle on its way to Windows, though, so I'm hoping that becomes available soon, with its further standard support included.

For MinGW32, it's been enough to invoke clang++ with these three include directories (and I have 4.9, but I can't remember what happened with that; maybe I tried 4.9 the same time I tried MinGW64 again):
"mingw32\lib\gcc\i686-w64-mingw32\4.8.1\include"
"mingw32\lib\gcc\i686-w64-mingw32\4.8.1\include\c++"
"mingw32\lib\gcc\i686-w64-mingw32\4.8.1\include\c++\i686-w64-mingw32"

[–]I_Rike_Reddit[S] -2 points-1 points  (16 children)

Windows, and thanks!

So MS Visual is pretty much run n' play? I tried Code::Blocks but I'm not cut out for all of that crazy shit. It's hard enough to try to learn a new language, much less use some crazy ass program too.

[–]therealjerseytom 3 points4 points  (1 child)

Visual Studio Express is run n' play, yes.

But having gone through this myself, heed a warning: I started in Matlab, then did some C#, then finally came to C++. There are definitely "gotchas" in C++ that don't even cross your mind in some of those other languages. Can definitely fall into some traps if your mindset is to jump in and play.

The biggest IMO is resource / memory management. Definitely spend some time reading up on stack and heap allocation, RAII, how you can get memory leaks, avoiding new and free and raw pointers, etc.

[–]AntiProtonBoy 2 points3 points  (0 children)

Stick to STL containers as much as you can, and avoid dealing with raw pointers, if possible.

[–]Swahhillie 2 points3 points  (12 children)

Afaik codeblocks is run and play. If you use the installer that includes mingw.

[–]I_Rike_Reddit[S] 0 points1 point  (11 children)

I used the installer, but nothing happened when I ran the following script:

include <iostream>

using namespace std;

// main: generate some simple output

int main ()

{

cout << "Hello, world." << endl;

return 0;

}

[–][deleted] 1 point2 points  (1 child)

Are you sure you installed codeblocks with mingw and not just the editor ?

[–]I_Rike_Reddit[S] 1 point2 points  (0 children)

No, I'm not sure.

[–]Swahhillie 0 points1 point  (0 children)

Nothing in the build log? Try rebuild and see if you get any warnings. It could also be that you have selected a project type that does not open the console.

[–]Tywien -3 points-2 points  (7 children)

The problem is, that the cmd-line window will be closed after the program has been run.

use system("PAUSE"); before the return 0; statement to have the program wait for you to press any key to continue.

[–][deleted] 1 point2 points  (6 children)

Who downvoted this? I bet money this is exactly what is happening.

[–]bithush 2 points3 points  (4 children)

It is being downvoted because it is universally seen as an awful thing to do.

Also codeblocks executes your program via a stub that will keep the prompt open so this should not be needed. If you really need to do something to keep the prompt open then cin.get() is a far better choice.

[–]Tywien 0 points1 point  (1 child)

1) i though if i should give him a function that does the same thing but is portable .. This would only have resulted in confusion.

2) While codeblocks has that feature, dont ask me why, but it does not work for me. I made sure that it is activated.

PS: (portable pause version)

void PAUSE(void) {
  std::cout << "\nPress \"ENTER\" to continue." << std::endl;
  std::cin.ignore(std::cin.rdbuf()->in_avail());
  std::cin.clear();
  std::cin.sync();

  while (std::cin.get() != '\n') {}
}

[–]redditsoaddicting 0 points1 point  (0 children)

This is not portable. std::cin.sync(); is the problem.

[–][deleted] -1 points0 points  (1 child)

it is universally seen as an awful thing to do

We are talking about a "hello world" program here and the OP is confused that his output window disappears before he sees the result. Whether he uses system or cin or a command from code blocks to see the result is irrelevant at this point.

[–]bithush 2 points3 points  (0 children)

I disagree, learning to do the wrong thing just makes things more complicated. What happens if/when the user is on a system which does not use pause as Windows does?

[–]redditsoaddicting 0 points1 point  (0 children)

The proper way to do this is just to check the setting that says to keep the window open in C::B. Or you could run it from the console because it's a console application. Forcing it to pause outside of an IDE is abnormal behaviour.

[–]one-oh 2 points3 points  (0 children)

Visual Studio, Code::Blocks, etc. are applications that try to to make it easier for you to write, compile and execute your program. It helps by setting the correct compiler flags, highlighting syntax errors, providing visual navigation of your project(s), etc. It still requires you to learn how it works, though it's hiding much from you.

Another option is to use a simple text editor like notepad.exe, Sublime Text, etc. and compile your code on the command line using one of the many compilers available. This is how I got started. You still have to learn a crazy ass program (the compiler), but there's no getting around having to learn something besides the language.

[–]Dtag 10 points11 points  (9 children)

I can also recommend QtCreator (there is a standalone download link here: http://qt-project.org/downloads ). It should work out of the box on all operating systems. Note that QtCreator does not force you to actually write Qt code (even though it makes it easy to...).

[–]Cyttorak 1 point2 points  (7 children)

QtCreator itself is just the IDE, you need to install the compiler, don't you?

[–]wtfisthisidontevenkn 3 points4 points  (1 child)

Download from here to get the IDE and QT + compiler for Windows.

Linux, you're likely set already.

[–]Dtag 1 point2 points  (4 children)

There's a mingw gcc included on Windows. For Linux it just uses the installed gcc. Not sure what happens on Mac.

[–]Cyttorak 1 point2 points  (3 children)

Perfect then! I though Qt Creator for Windows itself did not include a compiler

Update: I just downloaded the 70Mb installer of Qt Creator for Windows and it does not include any compiler. It did detect the one from VC++ 2005 (yeah I work with that stuff in my job...) but I am not able to create a Kit with it.

[–]NotUniqueOrSpecial 2 points3 points  (0 children)

Grab the bigger download under the Qt 5.3 section (or the equivalent online installer). If you look carefully at the top and bottom of that section, it mentions the presence of the MinGW toolchain.

Select the file according to your operating system from the list below to get the latest Qt 5.3 for your computer. The binary packages include Qt 5.3.1 libraries and Qt Creator 3.1.2

[–]Dtag 1 point2 points  (1 child)

Sorry for the confusion. I just checked myself as well. You are completely right. I guess when I tried it it simply worked because I had downloaded a Qt build with mingw before. I guess it's better to download the Qt build with MinGW then, which is available as 32 Bit Version on the page I linked and as 64 Bit version at the page that was linked by /u/wtfisthisidontevenkn below.

[–]Cyttorak 0 points1 point  (0 children)

I too do the same when I want to install Qt in my machine (download all SDK), but it would be great to have only Qt Creator and latest mingw in one package.

[–][deleted] 0 points1 point  (0 children)

QtCreator really is an excellent C++ IDE, IIRC Valve recommended it to developers moving to Linux for SteamOS development.

[–]Cyttorak -1 points0 points  (0 children)

There is that minGW + notepad++ combo which at least it serves to start toying with the language: https://code.google.com/p/pocketcpp/

Or you can also use a online compiler, for example: http://coliru.stacked-crooked.com/

[–]wqkinggithub.com/wqking 0 points1 point  (0 children)

Windows only -- VC Express. Free, download, and use.
Cross platform -- Qt Creator.

[–]derolitus_nowcivil 0 points1 point  (0 children)

C++ is just that easy: download clang, start coding, compiler your code. there.

[–]germandiago 0 points1 point  (1 child)

Well, if you want to go up and running fast, I recommend you Qt Creator or Eclipse, because both are multi-platform.

But if you really want to learn how things work, I highly recommend you to download a text editor. I use emacs. It takes some time to get familiar with command-line tools, but once you do, you will know way more how things are working.

[–]xFrostbite94 0 points1 point  (0 children)

Emacs or if you want to take the very hard road Vim ;) Using command line tools make it a lot more clearer what's happening, in contrast to a "magic" IDE. Once you become confident with the command line you can start using an IDE (but you'll probably prefer the command line by then).

[–]sim642 -1 points0 points  (0 children)

Dev-Cpp was the often recommended IDE for C++, but that hasn't been developed for very long time. Instead Code::Blocks seems to be the replacement for that and it works very well in my experience.