Outpost Universe Forums
Off Topic => General Interest => Topic started by: Larrythepoet on April 18, 2010, 06:25:52 PM
-
Alright, I've decided to start learning C++, but I am having a bit of trouble with it. I'm using code::blocks but I can't build the program I'm trying to run. Does anyone know a good compiler that's easy on beginners?
-
"not I" said the duck
-
I suppose you can try the free version from Microsoft. There used to be a Visual Studio 2008 Express editition, although, now it appears to be 2010.
http://msdn.microsoft.com/en-us/vstudio/default.aspx (http://msdn.microsoft.com/en-us/vstudio/default.aspx)
Or there's always good old g++ if you're on Linux.
I'd recommend the Microsoft Visual Studio C++ compiler for most Windows development.
-
Uhhh... So, you can't get something to compile, so obviously it must be the compiler's fault...?
Have you tried "Hello world"?
-
Yes, It says there is an incompatible compiler and that nothing can be done...
""Hello World - Debug" uses an invalid compiler. Skipping...
Nothing to be done."
-
Try copy-pasting some HelloWorld code from a website tutorial and see if it compiles. If not, you must be really good at breaking things.
Or, the more likely cause is you're doing something wrong. No offence meant, that's just the basic when someone picks up a program and has no idea what to do.
-
CodeBlocks isn't a C++ compiler. It's just an IDE. You need to supply a compiler separately. Usually it uses the Visual Studio compiler. Microsoft used to release the compiler without the IDE for free, so people used that with CodeBlocks. Now Microsoft releases a full IDE with their compiler, so there is probably little reason to use CodeBlocks. Plus, the few times I used CodeBlocks, it had a bit of a work in progress feel to it. I suspect it was never quite fully complete, and I kind of doubt there will be as much incentive to work on it with Microsoft's new free bundled packages.
I could be wrong though. CodeBlocks might be more cross platform or something. But it's still likely more work to setup. Just using Visual Studio is probably easier if that's an option for you. Considering it's free, and most internet connections these days won't choke on it's size, I'd say try that one first.
-
Alright, I thought the compiler was in Code::blocks... I'll try that tonight, thanks
-
You could also use gcc as compiler: http://wiki.codeblocks.org/index.php?title...ler#MinGW.2FGCC (http://wiki.codeblocks.org/index.php?title=Installing_a_supported_compiler#MinGW.2FGCC)
-
gcc is what a lot of college courses in C++ will have you use (but most of them will prefer unix/linux because it is, by far, a lot more coder friendly)
-
Ok, I made my first program with visual studios, thanks guys!
-
How do I store a string in a variable? I've tried using a "char" variable but I don't think I am doing it right...
char result;
...
...
if (x = y)
{
result="the same";
}
-
Have you tried string? :P
-
*cough* That might work... Thanks
-
Yay! I've written my first program. You type two different numbers and then it tells you if they are equal, the difference, the sum and the product!
-
can it tell you which one will win a 100 meter dash?
-
yea, the one that is lesser will win, as it has less weighing it down :P
-
I suppose I should mention that the "char" datatype only holds a single character. To hold more than one, you'd need an array of chars. Of course that brings up the issues of array length, and how arrays are treated (nearly) identically as pointers.
The array length is a memory allocation issue. Either set a fixed static size that is guaranteed to be big enough, or use dynamic memory allocation, which requires explicit new/delete (or malloc/free) calls, which can be expensive if called frequently.
The pointer issue is important when doing comparisons. If you wrote the code you have above, it would compare the pointers to each other. That is, it would compare the addresses of two strings in memory, rather than the contents of the two strings. Hence two strings with identical characters would compare differently because they are stored in different memory locations. You'd need to use a string comparison function, such as strncmp (or strcmp, if you don't know a max length, and there is no possibility of missing null terminators).
There are a number of string classes in C++ that basically wrap char arrays to handle the details for you, such as the CString class. I usually just end up using raw char arrays though, but then I don't usually do anything fancy with strings.
-
I strongly advice to use the STL string class. Its simpler than char arrays and part of the C++ standard (i.e. supported by every C++ compiler).
(There can still be reasons for using char arrays, such as keeping the binary small or in some rare cases avoiding some of the additional overhead)
-
and a char array would be great for an anagram solver
-
:blink:
-
:blink:
Yay! I've written my first program. You type two different numbers and then it tells you if they are equal, the difference, the sum and the product!
You probably should have stopped reading after that post.
-
I'll re-read it in a few weeks :P