Author Topic: I'm Trying To Learn C++  (Read 5310 times)

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« 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?
No.

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
I'm Trying To Learn C++
« Reply #1 on: April 18, 2010, 06:41:15 PM »
"not I" said the duck
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
I'm Trying To Learn C++
« Reply #2 on: April 18, 2010, 06:41:47 PM »
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

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.
 

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
I'm Trying To Learn C++
« Reply #3 on: April 18, 2010, 07:07:37 PM »
Uhhh... So, you can't get something to compile, so obviously it must be the compiler's fault...?

Have you tried "Hello world"?
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #4 on: April 18, 2010, 08:27:13 PM »
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."
« Last Edit: April 18, 2010, 08:29:09 PM by Larrythepoet »
No.

Offline Kayedon

  • Sr. Member
  • ****
  • Posts: 378
I'm Trying To Learn C++
« Reply #5 on: April 18, 2010, 08:58:37 PM »
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.
"Trust me, I'm crazy."

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
I'm Trying To Learn C++
« Reply #6 on: April 18, 2010, 11:41:43 PM »
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.
 

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #7 on: April 19, 2010, 07:39:04 AM »
Alright, I thought the compiler was in Code::blocks... I'll try that tonight, thanks
No.

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
I'm Trying To Learn C++
« Reply #8 on: April 19, 2010, 09:54:02 AM »

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
I'm Trying To Learn C++
« Reply #9 on: April 19, 2010, 11:23:07 AM »
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)
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #10 on: April 19, 2010, 04:13:09 PM »
Ok, I made my first program with visual studios, thanks guys!
No.

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #11 on: April 20, 2010, 08:03:19 PM »
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";
    }
No.

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
I'm Trying To Learn C++
« Reply #12 on: April 20, 2010, 08:15:13 PM »
Have you tried string?  :P  
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #13 on: April 20, 2010, 08:23:05 PM »
*cough* That might work... Thanks
No.

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #14 on: April 20, 2010, 09:15:06 PM »
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!
« Last Edit: April 20, 2010, 09:15:18 PM by Larrythepoet »
No.

Offline Spikerocks101

  • Hero Member
  • *****
  • Posts: 711
I'm Trying To Learn C++
« Reply #15 on: April 21, 2010, 12:18:00 AM »
can it tell you which one will win a 100 meter dash?
I AM YOUR PET ROCK!!!!!!

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
I'm Trying To Learn C++
« Reply #16 on: April 21, 2010, 01:41:20 AM »
yea, the one that is lesser will win, as it has less weighing it down :P
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
I'm Trying To Learn C++
« Reply #17 on: April 21, 2010, 01:49:51 AM »
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.

 

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
I'm Trying To Learn C++
« Reply #18 on: April 21, 2010, 12:30:28 PM »
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)
« Last Edit: April 21, 2010, 12:33:11 PM by TH300 »

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
I'm Trying To Learn C++
« Reply #19 on: April 21, 2010, 01:35:05 PM »
and a char array would be great for an anagram solver
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #20 on: April 23, 2010, 04:19:48 PM »
:blink:  
No.

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
I'm Trying To Learn C++
« Reply #21 on: April 23, 2010, 04:24:13 PM »
Quote
:blink:
Quote
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.
« Last Edit: April 23, 2010, 04:24:54 PM by Sirbomber »
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Larrythepoet

  • Jr. Member
  • **
  • Posts: 58
I'm Trying To Learn C++
« Reply #22 on: April 24, 2010, 11:13:22 AM »
I'll re-read it in a few weeks :P
No.