Page 1 of 2

Basic C++

Posted: Fri May 13, 2005 3:18 pm
by MikeDB
Hi all just wondering if anyone could teach me some basic C++ becuase i found that google aint so good.

Archived topic from Iceteks, old topic ID:3314, old post ID:26878

Basic C++

Posted: Fri May 13, 2005 5:13 pm
by Red Squirrel
Good luck with that. I know exactly how it is, I've been wanting to brush up C++ but it's hard to find the right resources, I find the basic stuff is the hardest. For example, I've been trying to turn a socket application into non blocking, and set a time out for connect for the longest time. I KNOW its something really simple, but it's the thing of knowing how to do it. And you can try C++ forums but I find C++ programmers tend to be rude about helping others, I don't know why. Lot of them assume you should just know stuff off the bat, but that's not how things work.

Feel free to ask your questions here and maybe someone can help, I think a few members here know C++ and I know enough to help with basic stuff though I have not programmed much in a while.

Books are the best bet, but they're bloody expensive, and hard to get in Canada unless you want to order from the US and pay insane shipping and border fees. But it IS an option, and probably the best way to learn.

Archived topic from Iceteks, old topic ID:3314, old post ID:26881

Basic C++

Posted: Fri May 13, 2005 5:26 pm
by Cold Drink
Look for Thinking in C++ and Beej's Guide to Network Programming. Both free and effective. Although both assume some level of competance with C, you can wing it without.

Archived topic from Iceteks, old topic ID:3314, old post ID:26884

Basic C++

Posted: Sat May 14, 2005 2:00 am
by MikeDB
hmmm well what about C? can someone bother with that? or maybe something else? I was hoping on making a thing so when you activated it, it had a popup that said "hello!"

Archived topic from Iceteks, old topic ID:3314, old post ID:26903

Basic C++

Posted: Sat May 14, 2005 10:57 am
by Red Squirrel
C++ is actually easier then C, at least I find. Only difference I know is i/o, and C++'s i/o is much easier. ex: you can go cout<<"string"<<variable<<"string"<<variable<<variable; and mix and match like that. In C, you'll have to have a bunch of printf's and all that, forget exactly how it works, I just know C++ is easier in that sense.

Archived topic from Iceteks, old topic ID:3314, old post ID:26904

Basic C++

Posted: Sat May 14, 2005 3:36 pm
by MikeDB
Ok cool... now i have to find someone who has alot of spare time on ther hands. :biglaugh:

Archived topic from Iceteks, old topic ID:3314, old post ID:26910

Basic C++

Posted: Tue May 17, 2005 8:56 pm
by wtd
If you're new to programming, why not take a look at a truly high-level programming language?

The biggest benefits is probably the presence of interactive interpreters in languages like Ruby, Python, Haskell, Scheme, and O'Caml.

Let's look at "Hello world" programs in a number of languages.

Code: Select all

/* C */

#include <stdio.h>

int main()
{
   puts("Hello world!");

   return 0;
}[code]

[code]// C++

#include <iostream>

int main()
{
   std::cout << "Hello world!" << std::endl;

   return 0;
}[code]

[code](* O'Caml *)

print_endline "Hello world!";;[code]

[code]-- Haskell

main = putStrLn "Hello world!"[code]

[code]# Perl

print "Hello world!
";[code]

[code]# Python

print "Hello world!"[code]

[code]# Ruby

puts "Hello world!"[code]

[code]; Scheme

(display "Hello world!")
(newline)[code]

[code]// D

int main()
{
   printf("Hello world!
");

   return 0;
}[code]

[code]// Java

public class HelloWorld
{
   public static void main(String[] args)
   {
      System.out.println("Hello world!");
   }
}[code]

[code]// C#

using System;

public class HelloWorld
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Hello world!");
   }
}[code]

[code]-- Eiffel

class HELLO_WORLD
creation make
feature
   make is
      do
         std_output.put_string("Hello world!")
         std_output.put_new_line
      end
end[code]

[code]-- Ada95

with Ada.Text_IO; use Ada,Text_IO;
procedure Hello_World is
begin
   Put_Line("Hello world!);
end Hello_World;[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3314, old post ID:26951[/size][/color]

Basic C++

Posted: Tue May 17, 2005 10:08 pm
by MikeDB
Ok i sort of get it. Now I have Edit Plus 2 if i were to use this would i put it in there and save it as a C++ file? (If i were to use C++)

Archived topic from Iceteks, old topic ID:3314, old post ID:26952

Basic C++

Posted: Tue May 17, 2005 10:12 pm
by Red Squirrel
I don't think extension matters but usually you save as a .cpp file and .h file for header files.

Archived topic from Iceteks, old topic ID:3314, old post ID:26953

Basic C++

Posted: Tue May 17, 2005 10:20 pm
by MikeDB
And that means?...

Archived topic from Iceteks, old topic ID:3314, old post ID:26955

Basic C++

Posted: Tue May 17, 2005 10:22 pm
by wtd
Red Squirrel wrote: I don't think extension matters but usually you save as a .cpp file and .h file for header files.
Accepted extensions for C++ source files are typically .cpp, .cxx, and .C. The latter is not looked upon well due to case-insensentive file systems. ".cpp" is usually preferred. ".h" is used for all header files. ".hpp" is an option, which differentiates between C and C++ header files, but is rarely used.

Archived topic from Iceteks, old topic ID:3314, old post ID:26956

Basic C++

Posted: Tue May 17, 2005 10:29 pm
by MikeDB
OOK i still dont understand what you are talking about but whatever.

Archived topic from Iceteks, old topic ID:3314, old post ID:26957

Basic C++

Posted: Tue May 17, 2005 10:37 pm
by wtd
I would highly recommend starting out with a language that has an interactive interpreter where you can enter code, run it and immediately see results. No saving to a file, compiling, running as separate steps.

Image

Archived topic from Iceteks, old topic ID:3314, old post ID:26960

Basic C++

Posted: Tue May 17, 2005 11:02 pm
by MikeDB
Ok and how do i do that?

Archived topic from Iceteks, old topic ID:3314, old post ID:26962

Basic C++

Posted: Tue May 17, 2005 11:21 pm
by wtd
Install the interpreters. :)

O'Caml
Ruby
Python
Haskell



Archived topic from Iceteks, old topic ID:3314, old post ID:26964

Basic C++

Posted: Tue May 17, 2005 11:56 pm
by MikeDB
Oki Doki

Archived topic from Iceteks, old topic ID:3314, old post ID:26972

Basic C++

Posted: Tue May 17, 2005 11:59 pm
by wtd
Once you're done that you'll have the various tools available in your Start menu somwhere. I'm in Linux at the moment (yes, they all work within Linux, Windows, Mac OS X, etc.), so I can't say for certain. :)

Archived topic from Iceteks, old topic ID:3314, old post ID:26973

Basic C++

Posted: Tue May 24, 2005 3:01 pm
by syb
I never heard of those except for Python. I looked each one up and read the short intro on them. I have a C++ for dumies book. I was going to try and give a crack but now I don't know weather I should. What's the major differnce between those and more commonly know C++ ?

Archived topic from Iceteks, old topic ID:3314, old post ID:27074

Basic C++

Posted: Tue May 24, 2005 5:50 pm
by wtd
Well, Python and Ruby are different in that they're not statically typed.

You see, in C++, every variable has a type.

Code: Select all

int a;
double b;[code]

"a" is an integer and "b" is a double precision floating point number.

However, the value stored in the variable has no type.

Now, in Python and Ruby it's exactly the opposite.  The value has a type, and the variable doesn't.  The variable is just a name.  I can reuse the name for an entirely different kind of value.

I could assign a value of 5 to "a", then immediately afterwards assign a string to the same variable.

[code]a = 5
a = "hello"[code]

This is perfectly legal in both Python and Ruby (and at least here they have the same syntax).

The way things are enforced in this kind of situation is what's often called "duck typing".  That is, if my code wants a duck, and I give it something that quacks like a duck and walks like a duck, then what I've given it might as well be a duck.  :)

Ruby and Python also feature more friendly syntax than C++.  It's more straightforward.  In C+ the keyword "const" can have about half a dozen different meanings depending on where it is.  This certainly gives the language flexibility, but it comes with a steep learning curve attached, and that steep learning curve can be frustrating.

Both languages make it easier to deal with object-oriented programming, and they feature conveniences for even simpler bits of code.  Want to loop over an array in Python or Ruby, as compared to C++?

C++
[code]int a[] = {3, 4, 5, 1, 2, 9, 8};

for (int i(0); i < 7; ++i)
{
   std::cout << a[i] << std::endl;
}[code]

Python:
[code]a = [3, 4, 5, 1, 2, 9, 8]

for x in a: 
   print a[code]

Ruby:
[code]a = [3, 4, 5, 1, 2, 9, 8]

for x in a 
   puts x
end[code]

Ruby (other option):
[code]a = [3, 4, 5, 1, 2, 9, 8]

a.each { |x| puts x }[code]

Now, O'Caml and Haskell are a bit different.  They are statically-typed like C++, but they infer types based on how you use values.  They also support generics much better than C++, and generally provide lots of syntctic convenience.

They make implementing data structures beautiful.  Let's consider creating a binary tree.

C++
[code]#include <iostream>

template <typename T>
class binary_tree_node
{
   private:
      const T value;
      binary_tree_node<T> * left, * right;
   public:
      binary_tree_node(T init_value)
      : value(init_value)
      , left(NULL), right(NULL)
      { }

      binary_tree_node(T init_value, binary_tree_node<T> * l, binary_tree_node<T> * r)
      : value(init_value)
      , left(l), right(r)
      { }

      ~binary_tree_node()
      {
         if (left) delete left;
         if (right) delete right;
      }

      int length() const
      {
         int len(1);
         if (left) len += left->length();
         if (right) len += right->length();
         return len;
      }
};[code]

O'Caml:
[code]type 'a binary_tree = Empty | Leaf of 'a | Branch of 'a binary_tree * 'a * 'a binary_tree;;

btree_length tree = 
   match tree with
      Empty -> 0
    | Leaf _ -> 1
    | Branch (l, _, r) -> 1 + btree_length l + btree_length r;;[code]

Haskell:
[code]data BinaryTree a = Empty | Leaf a | Branch (BinaryTree a) a (BinaryTree a)

btreeLength Empty = 0
btreeLength (Leaf _) = 1
btreeLength (Branch l _ r) = 1 + btreeLength l + btreeLength r[code]

And for all four, with some exceptions in Haskell's case, you needn't create any source files or do any compilation.  Just type your code at the prompt and hit return. 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3314, old post ID:27078[/size][/color]

Basic C++

Posted: Tue May 24, 2005 6:08 pm
by Red Squirrel
Actually when I started learning php (alreading knowing C++) I found that to be nice that you don't have to define types. Saves allot of headaches I find, for example a function that needs a char, but some other function returns a Cstring, then you have to somehow convert it to char so you can use the function. In php you don't have to worry about that. Php variables are also unlimited, well limited to memory I guess. But what's nice is you don't have to pre-allowcate the memory for each var.

I once found a way to run php as an interpreter and type commands directly in it and get the result, but I just checked and can't seem to find it now.

Archived topic from Iceteks, old topic ID:3314, old post ID:27079

Basic C++

Posted: Tue May 24, 2005 8:32 pm
by syb
Interesting.. I am defiantly going to look into to it. Just one thing. Commercially which is used more often or are some better then others for a specific type of programing?

Archived topic from Iceteks, old topic ID:3314, old post ID:27082

Basic C++

Posted: Tue May 24, 2005 8:53 pm
by Red Squirrel
C++ is probably the most comonly used language for applications, while php and asp are the in the lead in terms of web based programming, php is probably more widely used. asp is Microsoft's version of php. Not sure wether or not it's good as I've never tried it, but some sites (such as a MS's :P) do use it.

Visual basic is another one that has not been mentioned, but it's ...basic. Personally I don't like it, the syntax is just way off track compared to other languages. It will do nothing but confuse you if you are learning another language at the same time. But it can be useful for making quick windows based applications.

Archived topic from Iceteks, old topic ID:3314, old post ID:27084

Basic C++

Posted: Tue May 24, 2005 10:19 pm
by wtd
syb wrote: Interesting.. I am defiantly going to look into to it. Just one thing. Commercially which is used more often or are some better then others for a specific type of programing?
That's a very complicated question, so it deserves a thorough answer.

Certainly C and C++ are used very widely in the business world. Java is becoming their new mainstay as well. Visual Basic and C# will be relevant simply due to Microsoft's influence on the market.

That pretty much covers the widespread, really boring "corporate" languages. :)

Now, what about the interesting ones?

Well, Objective-C is the language of choice for Mac development. It uses the Cocoa framework, which is just a work of art and a joy to use. Obviously, the Mac market is relatively small, comparatively, but it's an enthusiastic market, and that counts for a lot. You canw rite a killer program for Windows and you'll find there are already ten other programs that do the same thing. There're still lots of opportunities on the Mac side of the fence to make an impact.

Ada is big in the aerospace and defense industries. It's taken a lot of abuse, but it has a lot of really neat features, and the fact that it's relatively low-profile means there might be good opportunities if you can put it on your resume.

Python is the new Java. It's getting lots of hype, and lots of use at places like ILM and notably in the next version of Civ3, among many other uses. I believe Google even gives preference or did to programmers with Python in their toolbox.

If Python is the new Java, then Ruby is the new Python. It's exciting and it's starting to get a lot of attention due to Ruby on Rails, an amazingly easy framework for building web applications. Definitely worth checking out to "get in on the ground floor".

O'Caml is gaining popularity, mostly as an alternative to C++ which offers really fast executables and easier coding.

Haskell is mostly academic, but it has a lot to teach. Haskell programmers are better C++ programmers.

In conclusion...

I've learned a lot of programming languages over the years, so take it from me, it gets easier each time.

Since it gets easier each time, your best bet is to learn the languages that make it easiest first. You hae time before you're going to be looking for a programming job anyway, so learn a few other languages like Ruby, Python, or O'Caml before C++ or even Java.

The biggest stumbling block I think is going to be object-oriented programming, and wrapping your mind around it. It was for me (until I got to the serious functional programming).

You're going to be happy for an interactive interpreter when you're trying to grasp concepts like inheritance, encapsulation, and polymorphism. You're going to write a lot of stupid little classes that do nothing, and having to go through the "edit, save, compile, run" process each time you make a change will get frustrating.

In conclusion: don't worry about which language is used the most. Pick the one that'll make learning concepts the easiest. Save the hard stuff for later.

Archived topic from Iceteks, old topic ID:3314, old post ID:27086

Basic C++

Posted: Wed May 25, 2005 2:54 pm
by syb
I think i'll start with python. Thank you for the info.

Archived topic from Iceteks, old topic ID:3314, old post ID:27092

Basic C++

Posted: Wed May 25, 2005 3:23 pm
by wtd
Feel free to ask Python questions.

Archived topic from Iceteks, old topic ID:3314, old post ID:27093