Computer Science Canada

How do you run code in C++??

Author:  livingheaven [ Sun Mar 21, 2010 5:30 pm ]
Post subject:  How do you run code in C++??

How Do you run code in C++???

Author:  Sur_real [ Sun Mar 21, 2010 5:33 pm ]
Post subject:  RE:How do you run code in C++??

do you mean using a compiler?

Author:  TerranceN [ Sun Mar 21, 2010 5:44 pm ]
Post subject:  RE:How do you run code in C++??

Please read this tutorial.

Hope thats what you were looking for.

Author:  Insectoid [ Sun Mar 21, 2010 5:50 pm ]
Post subject:  RE:How do you run code in C++??

You'll be needing to get a compiler. One is included with at least some Linux distro. Macs have g++ included in their developer tools which come on the OS X installation disk. You'll have to download one for Windows. Don't ask me how to install it on Windows, I don't know. Once it's installed, single-file scripts can be executed by typing 'g++ <filename>' in the terminal. Dunno how this works on Windows, once again. Lager projects will require a makefile. If you've downloaded source code the makefile will prolly already be included, in which case type 'make <filename>' and if applicable, 'make install <filename>'. I don't know the specifics and of course I don't know how any of this works on Windows. There is a tutorial around here somewhere (a rather new one I believe, unless someone necro'd it to lead me to believe it was new) that you can check out that goes into specifics about makefiles.

Author:  DtY [ Sun Mar 21, 2010 5:51 pm ]
Post subject:  RE:How do you run code in C++??

Generally, the process is something like this:

- Compiler: Each source file compiled into a machine dependent assembly language
- Assembler: Assembled into object files, which are nearly executables, but contain symbols so other objects can find resources (functions, classes, &c) in it.
- Linker: Objects are linked together along with runtime stuff that sets up the environment (which will then call your main()), this step produces an executable file (if you're on Windows, it's a .exe).
- Loader: The executable is loaded into memory, and launched by the operating system.

You really only need to be concerned with the compiler and linker, generally the assembler step is automatic, and the loader is invoked like for any other executable (double click on Windows, or ./executable on *nix).

If you're using an IDE, look for a button that says Build and Run, or something similar.

[edit] Insectoid's instructions are probably more what you were looking for

Author:  Insectoid [ Sun Mar 21, 2010 5:54 pm ]
Post subject:  RE:How do you run code in C++??

Found the link (d'oh, was the first sticky in C++ Tutorials) http://compsci.ca/v3/viewtopic.php?t=9420

Oh, and the compiler or whatever is gcc, not g++.

Author:  livingheaven [ Mon Mar 22, 2010 7:09 pm ]
Post subject:  Re: How do you run code in C++??

Shocked wow this is a lot of work just to get C++ started .........
BTW thanks for the help

Author:  Insectoid [ Mon Mar 22, 2010 7:15 pm ]
Post subject:  RE:How do you run code in C++??

It's the same for most compiled languages (or at least, very similar). Interpreted languages require an interpreter installed, much in the same way. Install one and you can install 'em all.

Author:  Kharybdis [ Mon Mar 22, 2010 9:50 pm ]
Post subject:  Re: How do you run code in C++??

I would suggest starting with the dev c++ compiler (my bias is because it runs on usbs Razz ).

It's really easy to use.

Link for the desktop version.

Link for the portable version.

If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.

For dev c++, just include everything that you would in a program such as 'hello world', and run the button that says 'run and compile'. Kinda obvious, actually. If you have more than one file (eg. .cpp and .h files), you're going to have to make a project, associate all the files that you need with that project, and once again, compile and run the project.

A useful command to know right away is 'system("pause"). Put that right before your return statements, as it makes you enter a key before the program exits. Otherwise, you're going to have a dos-like prompt flash at you and close, which is annoying to say the least.

Author:  wtd [ Tue Mar 23, 2010 12:19 pm ]
Post subject:  Re: RE:How do you run code in C++??

Insectoid @ Mon Mar 22, 2010 6:54 am wrote:
Found the link (d'oh, was the first sticky in C++ Tutorials) http://compsci.ca/v3/viewtopic.php?t=9420

Oh, and the compiler or whatever is gcc, not g++.


GCC is the GNU Compiler Collection. "gcc" and "g++" are both front-end programs to that collection. Given the correct arguments passed to it, "gcc" can be used for C or C++ (or any number of other languages) programs.

Author:  wtd [ Tue Mar 23, 2010 12:21 pm ]
Post subject:  Re: How do you run code in C++??

Kharybdis @ Tue Mar 23, 2010 10:50 am wrote:
If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.


Dev C++ and Visual C++ are both integrated development environments. This means that they usually bundle up a compiler, but also include a bunch of other crap to scare off novice programmers.

Vi and nano are both just text editors, and will not serve to compile C++ code.

Author:  wtd [ Tue Mar 23, 2010 12:24 pm ]
Post subject:  RE:How do you run code in C++??

Given the level of knowledge I'm detecting in this thread, C++ is not a good language for you to be tackling right now. C++ is not a beginner language.

There are any number of other better choices.

Author:  USEC_OFFICER [ Tue Mar 23, 2010 12:30 pm ]
Post subject:  RE:How do you run code in C++??

Like? Give a few examples for the guy, he can't read minds you know. (I'm not going to bring up the story.)

Author:  chrisbrown [ Tue Mar 23, 2010 1:43 pm ]
Post subject:  RE:How do you run code in C++??

My two cents: Python, Ruby, or Scheme. None require any extraneous code to get a working program, so it is easy to get started immediately; however all are scalable to be useful for large projects as well (classes, abstraction, etc...), so there is no ceiling as to what you can learn.

Author:  Kharybdis [ Tue Mar 23, 2010 1:56 pm ]
Post subject:  Re: How do you run code in C++??

wtd @ Tue Mar 23, 2010 12:21 pm wrote:
Kharybdis @ Tue Mar 23, 2010 10:50 am wrote:
If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.


Dev C++ and Visual C++ are both integrated development environments. This means that they usually bundle up a compiler, but also include a bunch of other crap to scare off novice programmers.

Vi and nano are both just text editors, and will not serve to compile C++ code.


my bad. yah, they are text editors. in linux, i just make .cpp or .h files in vi or nano and then run them by using g++. You mention that the IDEs scare the novice programmers, but if you want to learn c++, they're still the best option.
I agree with you though that Python would be a better language to learn first because of its gradual learning curve and ease of use. t

Author:  wtd [ Wed Mar 24, 2010 9:40 am ]
Post subject:  Re: How do you run code in C++??

[quote="Kharybdis @ Wed Mar 24, 2010 2:56 am"]
wtd @ Tue Mar 23, 2010 12:21 pm wrote:
Kharybdis @ Tue Mar 23, 2010 10:50 am wrote:
If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.


Dev C++ and Visual C++ are both integrated development environments. This means that they usually bundle up a compiler, but also include a bunch of other crap to scare off novice programmers.

Vi and nano are both just text editors, and will not serve to compile C++ code.


my bad. yah, they are text editors. in linux, i just make .cpp or .h files in vi or nano and then run them by using g++. You mention that the IDEs scare the novice programmers, but if you want to learn c++, they're still the best option./quote]

No. They're not. C++ is a "get your hands dirty with nitty gritty details" language. It is beneficial to work with a (decent) text editor and command-line compiler.

Author:  TheGuardian001 [ Wed Mar 24, 2010 2:38 pm ]
Post subject:  Re: How do you run code in C++??

If anything IDE's are much friendlier to newer people, since they don't require mucking around in command line, providing a simple "do everything and run" button.

Of course, having a "do everything" button also tends to give you at least a bit less control over the compile process, and also puts quite a bit of overhead on compiling. If you really want to be developing in C++, you'll have to know command line compiling eventually. It's more difficult to get the hang of, but it's still the better option.

Author:  DtY [ Wed Mar 24, 2010 4:17 pm ]
Post subject:  RE:How do you run code in C++??

I don't like IDEs, but can you imagine trying to teach 30 students how to (1) use the command line (2) start the compiler (3) why you should do the compiling and linking in two steps, when you can do everything in one step (3) how to write a makefile

Pretty much all before you start to write any programs?

[edit] Scons might not be a bad idea to teach instead of an IDE though, it's basically an IDE without the text editor, and exposes some of the low level compiler stuff.

Author:  wtd [ Wed Mar 24, 2010 11:27 pm ]
Post subject:  RE:How do you run code in C++??

I feel like a broken record.

If you just want to get down to writing programs, C++ is the wrong language.

Author:  USEC_OFFICER [ Thu Mar 25, 2010 11:08 am ]
Post subject:  RE:How do you run code in C++??

Yah, try Python. It's quite swell.

Author:  apomb [ Thu Mar 25, 2010 1:19 pm ]
Post subject:  RE:How do you run code in C++??

or ruby

or you could try shoes... seems that all of the shoes links are broken here here though... sad.

edit: http://shoes.heroku.com/ is the new home of shooooes.

thank you for listening.

goodday

Author:  andrew. [ Thu Mar 25, 2010 3:54 pm ]
Post subject:  RE:How do you run code in C++??

Yeah I think Ruby or Python would be the best choices for a first programming language because they are easy to learn, but also because they don't need to be compiled.

Author:  USEC_OFFICER [ Thu Mar 25, 2010 5:42 pm ]
Post subject:  RE:How do you run code in C++??

Plus Python syntax is so simple. The indentations are the formating. eg. They replace the brackets in C++. I have no idea about Ruby though. Only that Google uses it.

Author:  DtY [ Thu Mar 25, 2010 6:13 pm ]
Post subject:  Re: RE:How do you run code in C++??

USEC_OFFICER @ Thu Mar 25, 2010 5:42 pm wrote:
Plus Python syntax is so simple. The indentations are the formating. eg. They replace the brackets in C++. I have no idea about Ruby though. Only that Google uses it.
Ruby has two different syntaxes for blocks, depending on what you're doing. The first has an implicit start, after a conditional, loop or function definition, and either do...end or {...} for blocks, which are pretty much anonymous functions.

Author:  livingheaven [ Sat Mar 27, 2010 4:48 pm ]
Post subject:  Re: How do you run code in C++??

thx guys Very Happy

Author:  livingheaven [ Sat Mar 27, 2010 4:50 pm ]
Post subject:  Re: How do you run code in C++??

right now im using turing, but i thought turing is limited so i decided to go in C++

Author:  TheGuardian001 [ Sat Mar 27, 2010 5:11 pm ]
Post subject:  Re: How do you run code in C++??

C++ is not generally a good first step out of Turing... I'd definitely recommend going to something a bit easier to learn, like Python or Ruby, before working your way up to C++.

Although neither of them are compiled languages (meaning that anybody who wants to run them needs an interpreter, and has access to the source), they do have quite a bit of power in them and are much easier to simply write and run.

Still, I suppose that if you're really set on learning C++, there's nothing out there to stop you. Plenty of people have learned C/C++ just by diving into it, so if you think you're up for it, more power to you.

Author:  TerranceN [ Sat Mar 27, 2010 5:35 pm ]
Post subject:  Re: How do you run code in C++??

livingheaven @ Sat Mar 27, 2010 4:50 pm wrote:
right now im using turing, but i thought turing is limited so i decided to go in C++


But is it actually limiting to you? Don't decide not to use a language just because some people don't like it. Besides, by the time you find Turing limiting, you will be able to easily learn a new language.

Author:  wtd [ Sat Mar 27, 2010 10:11 pm ]
Post subject:  Re: How do you run code in C++??

livingheaven @ Sun Mar 28, 2010 5:50 am wrote:
right now im using turing, but i thought turing is limited so i decided to go in C++


Kind of like saying: "I hate the kiddie pool, so I'm going diving in the Mariana Trench."

Author:  SNIPERDUDE [ Sun Mar 28, 2010 12:42 pm ]
Post subject:  RE:How do you run code in C++??

Ah, vacation of '98. Thems was good times.

Author:  CodeMonkey2000 [ Sun Mar 28, 2010 1:01 pm ]
Post subject:  RE:How do you run code in C++??

I'd recommend using scite as your text editor, and using command line to compile things. Once you are comfortable with command line, move on to makefiles. Since you are using C/C++, running with valgrind is helpful in finding memory leaks (but it's not perfect). Problem is that I think valgrind only works in linux. I'm not sure.

I assume you want to learn C/C++ to make games?


: