STL for a C programmer

A

Albert

Hello,

For coding contests I only have a solid knowledge of C. When problems
get hard, I won't have time to code up my own Andersson tree but will
have to use a binary search tree in the STL.

Is there a good tutorial on C++ you would recommend, covering especially
the STL, on the internet for C programmers? I need a solid understanding
of C++ programs that are the C++ version of the C counterpart (so I can
found out what I need to #include, what using namespace std means), and
don't need OOP *at all* (but I think the STL requires understanding of
OOP, I'm not sure).

TIA,

Albert
 
L

Leo Havmøller

Albert said:
Hello,

For coding contests I only have a solid knowledge of C. When problems get
hard, I won't have time to code up my own Andersson tree but will have to
use a binary search tree in the STL.

Is there a good tutorial on C++ you would recommend, covering especially
the STL, on the internet for C programmers? I need a solid understanding
of C++ programs that are the C++ version of the C counterpart (so I can
found out what I need to #include, what using namespace std means), and
don't need OOP *at all* (but I think the STL requires understanding of
OOP, I'm not sure).

I recommend the book "Accelerated C++" by Andrew Koenig and Barbare E. Moo:
http://www.amazon.com/Accelerated-C...=sr_1_1?ie=UTF8&s=books&qid=1264049594&sr=8-1

Leo Havmøller.
 
B

Bas

IMHO I dont think you can understand STL really well if you don't know C++
really well.

Bas
 
R

Rune Allnor

Hello,

For coding contests I only have a solid knowledge of C. When problems
get hard, I won't have time to code up my own Andersson tree but will
have to use a binary search tree in the STL.

Is there a good tutorial on C++ you would recommend, covering especially
the STL, on the internet for C programmers? I need a solid understanding
of C++ programs that are the C++ version of the C counterpart (so I can
found out what I need to #include, what using namespace std means), and
don't need OOP *at all* (but I think the STL requires understanding of
OOP, I'm not sure).

Having made the transition from C to C++ *mindsets* over
the past few years, my experience is simple, if a bit
discouraging from your POV:

If you want to make the transition, be prepared to spend a
*lot* of time unlearning C and learning the C++ counterpart.

The problem is that C is a subset of C++, and the code might
at first glance look similar, which in turn might cause C
programmers to think the transition is a simple matter,
learning a couple of new libraries and/or keywords.

However, the ideas and mindsets behind C and C++ programs
are totally different. You don't need to go to OO at all to
see the difference: Templates and / or type-dependent argument
look-up in functions are more than enough to get you into
serious... if not trouble so at least cause you to write
seriously poor C++ programs.

If you do not want to spend the time on the transition, you
might be better off staying completely in the C world.

Rune
 
B

Bas

Francis Glassborow said:
However you do not need to understand it in order to use it. E.g.

std::vector<T>

all the user needs to know is that creates an expendable sequence of T.

...I think you need at least some knowlegde of templates. If T is a compound
object (Base and derived class) you need to know etc.
I doubt one can use the STL without knowing C++.

Bas
 
B

Bas

Rune Allnor said:
Having made the transition from C to C++ *mindsets* over
the past few years, my experience is simple, if a bit
discouraging from your POV:

If you want to make the transition, be prepared to spend a
*lot* of time unlearning C and learning the C++ counterpart.

The problem is that C is a subset of C++, and the code might
at first glance look similar, which in turn might cause C
programmers to think the transition is a simple matter,
learning a couple of new libraries and/or keywords.

However, the ideas and mindsets behind C and C++ programs
are totally different. You don't need to go to OO at all to
see the difference: Templates and / or type-dependent argument
look-up in functions are more than enough to get you into
serious... if not trouble so at least cause you to write
seriously poor C++ programs.

If you do not want to spend the time on the transition, you
might be better off staying completely in the C world.

Rune

I agree completely!

Bas
 
A

Alan Woodland

Rune said:
Having made the transition from C to C++ *mindsets* over
the past few years, my experience is simple, if a bit
discouraging from your POV:

If you want to make the transition, be prepared to spend a
*lot* of time unlearning C and learning the C++ counterpart.

The problem is that C is a subset of C++, and the code might
at first glance look similar, which in turn might cause C
programmers to think the transition is a simple matter,
learning a couple of new libraries and/or keywords.

However, the ideas and mindsets behind C and C++ programs
are totally different. You don't need to go to OO at all to
see the difference: Templates and / or type-dependent argument
look-up in functions are more than enough to get you into
serious... if not trouble so at least cause you to write
seriously poor C++ programs.

If you do not want to spend the time on the transition, you
might be better off staying completely in the C world.
On the bright side though the first time someone said "iterators are a
generalisation of the concept of a pointer" the STL made a heck of a lot
more sense to me coming from a C background!

Alan
 
A

Albert

Yannick said:
I think the point is the the OP (Albert) fears that using C++ would
require him to switch completely to Object Oriented programming rather
than the functional programming style that is more common in C and
that he has been using for years and that he is familiar and
confortable with.
<snip>

Not quite. In coding contests, everyone I know uses a functional
programming style, it's just that they are about getting the algorithms
right in a limited time, not spending half the time debugging the
various operations/functions for the sometimes tricky data structures
required (eg. height-balanced binary search trees, *maybe* the
heap-based priority queue and the disjoint set operations for
Kruskal's). I'm keeping in mind that at international level (ie. the
IOI), no reference materials can be brought in by people, and the
computers only provide STL docs and C reference.
 
B

Bo Persson

Alan said:
On the bright side though the first time someone said "iterators
are a generalisation of the concept of a pointer" the STL made a
heck of a lot more sense to me coming from a C background!

Alan

And for me, with a C++ background, it was a really great moment when I
found the statement:

"A pointer is a kind of random-access iterator"

(Koenig & Moo)


at a point where this made perfect sense. :)



Bo Persson
 
K

Keith Thompson

Albert said:
Not quite. In coding contests, everyone I know uses a functional
programming style, it's just that they are about getting the
[snip]

I don't think "functional programming style" is really what
you mean. A functional programming style is common in Lisp and
similar languages. The most common programming style in C is an
imperative or procedural style.
 
A

Albert

Keith said:
Albert said:
Not quite. In coding contests, everyone I know uses a functional
programming style, it's just that they are about getting the
[snip]

I don't think "functional programming style" is really what
you mean. A functional programming style is common in Lisp and
similar languages. The most common programming style in C is an
imperative or procedural style.

Yep, you're right; that is indeed what I meant :)
 
A

Albert

Albert said:
<snip>
Is there a good tutorial on C++ you would recommend, covering especially
the STL, on the internet for C programmers?
<snip>

Read up to Chapter 17 of http://www.4p8.com/eric.brasseur/cppcen.html;
that should be enough information about templates to move on to
http://www.sgi.com/tech/stl/stl_introduction.html. That should be enough
to get though most of the documentation after reading the section about
iterators.

This should be enough for C programmers to be able to basically use the
STL when time is short for coding up tricky data structure operations :)

P.S. Where's the balanced binary search tree in the STL?

Albert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top