C Plus Plus Primer

Stanley B. Lippman, Josée Lajoie, Barbara E. Moo

Mentioned 14

A best-seller completely revised and rewritten to conform to today's C++ usage.

More on Amazon.com

Mentioned in questions and answers.

I have a Phone interview coming up next with with a company which works in financial software industry. The interview is mainly going to be in C++ and problem solving and logic. Please tell me the method of preparation for this interview. I have started skimming through Thinking in C++ and brushing up the concepts. Is there any other way I can prepare?? Please help.

Edit:

Thank you all everyone for the advice. I just want to add that I am currently fresh out of grad school and have no previous experience. So Can you suggest some type of questions that will be asked to new grads??

Read (or skim, depending on how much time you have to prepare) "Large-Scale C++ Software Design" by John Lakos. Chances are, you will need it.

Make sure you know your basic data structures and algorithms. You're more likely to be asked about that stuff than something higher up the food chain. Those are usually saved for the in-person interview.

Put another way: be solid with the fundamentals and solid with your C++ syntax. Also, knowledge of common libraries like STL and Boost couldn't hurt...but be sure you know what those libraries give you! In the end phone screens are there to cull out people who can't do the basics. Prove you can and you should move on to the next step. Good luck!

Here's some links of interview questions to check out:

Now, for completion's sake, some books:

I've recently started to learn C++ and am completely confused with the choices of IDEs and compilers out there. I am competent with interpreted languages and like the simplicity of using any IDE or text editor and then running the interpreter from the command line. Everything works as I expect, regardless of the IDE used, because I use the same interpreter each time.

Now that I have started learning C++ I am overwhelmed by the choice of different compilers and more importantly, their differences. It seems that things will be simpler for me (not necessarily easier) if, while learning, I use a text editor and a compiler that I run from the command line. I have a basic understanding of how compiling and linking works and I understand the role of header files.

Firstly, are there any books or websites that teach C++ from this approach? (IDE-less) Many books try to point out the differences between IDEs and compilers by selecting two and comparing them, which confuses me.

Secondly, how should I set up my workflow? (Ignore the choice of text editor, I am talking about compilers, linkers etc.) I am struggling to understand what differences different compilers have and so please bear this in mind when answering. It seems like the most popular compilers are g++ and CL. Similar question but I am more interested in why some programs will work with some compilers and not others: C++ Compiler for Windows without IDE?

Further information: I am developing on Windows and from what I understand, it seems that there is 'pure' C++ and then C++ that is somehow related to windows, is this Visual C++? I would like to write programs that make use of Windows features but I want to know when I am using windows features and when I am writting code that would work on any platform.

Update: So it seems that I shouldn't be worrying about compilers when I am just starting out. The reason for me wanting to understand the differences is because I don't want to write code for a specific compiler and get into bad habits. Is this a non-issue?

Firstly, are there any books or websites that teach C++ from this approach? (IDE-less)

Yes, definitely. Stroustrup's book has already been mentioned. For learning C++ I'd also recommend two other books: If you like thorough explanations and don't shy away from 1000 pages, look at Lippman et al. If you rather like a short introduction and don't fear a steep learning curve, look at Koenig/Moo. Both are excellent books. (BTW, a good place to look for good books has always been the book review section at the ACCU.)

As for which tool chain you want to use: If you rather have a standalone editor and invoke the compiler from the command line, you can do this with either GCC or VC. This approach has the advantage that it is more unlikely to lure you into using something proprietary (like C++/CLI). If you would like to try an IDE, VC Express is fine, once you're past setting up a new C++ project. Of course, the number of options you can tweak for a new project can be very overwhelming. But on the other hand you get things like an integrated debugger. Note that there are other integrated solutions, too. The most mature and prominent is probably eclipse.

Edit: If you don't mind spending a little money, look at Comeau. It's not free, but it's not expensive either and it's usually considered to be the most standard-conforming C++ compiler around and has excellent error messages. (You can test-drive it at the website.) Note that it emits C code, though. That means you have to have another compiler to create an executable program. But both GCC and VC Express will do, so there's no other cost. (Note that using VC you will get Dinkumware's std lib implementation, which is also considered to be a very good one.)

Im trying to learn OOP but I need to see some real case scenarios of using C++. For me, as a beginner in programming internet is too big and the book is too few examples. All I find on the source repositories are large projects or too few details.

Can you give me a link to some c++ projects which are good for beginners? It will be great if the samples have some details about good practices.

maybe some universities are hosting such projects or maybe you know a webpage with samples and contests about how to program in C++ and it is good for beginners.

You can take a look at this C++ book: C++ Primer which has good practice exercises and there is also a Answer book for the exercise problems.

What is the proper use of the this self-reference of a class?

I sometimes use it inside a method to clear out that the variable used is a member variable and not one declared inside the method, but on the other side I am wondering if this is a good reason to do so, as I think you should always code (and comment) in a way which is self-explaining and therefore would make such an unneeded use of this unnecessary and another reason against it would be that you are actually producing more code than needed.

void function() {
  while(i != this->length) //length is member var
     /*do something*/
}

Another way of using it I frequently encounter is inside constructors (mostly in Java), as the parameters do have the same name as the member variables which has to be initialized. As the Primer states that this is bad code I am not doing this, but on the other side, I see how using the same name as the member-vars as parameter names clears out of which use they are.

C++
Constructor::Constructor(int size,int value) : this->size(size),
                                               this->value(value) {};

Java
Constructor(int size,int value) {
  this->size = size;
  this->value = value;
}

I hope there is actually a rule considering both languages (Java/c++), if not I will retag for just c++ as this is the one I am more interested in.

For the most part, this-> is redundant. The exception is if you have a parameter or a local variable of the same name (easily, and probably best avoided), or in a template, in order to force the following symbol to be dependent—in this latter use, it is often unavoidable.

I'm learning C++ with codeblocks and I'd like to ask if you can post me some good pointers how I can learn the difference between MinGW and Visual studio C++, for example \n and << don't always behave as I'm expecting. I'm complete newbie, only reached day 2 of an old book "Teach yourself C++ in 21 days" by Jesse Liberty and the program looks like this:

#include <iostream>

using namespace std;

    int main()
    {
        cout << "Hello there."; endln;
        cout << "Here is 5: " << 5 << endl;
        cout << "The manipulator endln writes a new line to the screen";
        cout << "Here is a very big number:\t" << 70000;
        cout << "Here is the sum of 8 and 5:\t" << 8+5;
        cout << "Here is a fraction:\t\t" << (float) 5/8;
        cout << "And here is a very big number:\t" << (double) 7000*7000;
        cout << "Remember to replace Niklas with you name";
        cout << "Hampus is a C++ programmer!";
        return 0;
    }

Is MinGW C++ the same as GNU C++? Is there an official standard? any advice for newbie learning / teaching will be appriciated. The book I'm following is "Teach yourself C++ in 21 days" and it is and old edition of the book but I could modify the programs from the first exercise to run and I believe I can use the book since perhaps not many changes were made to the basic C++ since it was published (the edition of the book I own is maybe 10 years old).

Thank you!

Update After getting the recommendations here, I've bought the book C++ Primer.

The only thing that compiler has to enforce (or SHOULD enforce :P) is stuff that's written in standard. Standard defines behavior, not the implementation, therefore compilers can differ.

First of all, code::blocks is not a compiler, it's an environment in which people usually use MinGW compiler. Visual Studio on the other hand is an environment that just happens to come with it's own compiler.

Differences between compilers should be of no concern for you as a beginning c++ programmer and text editor or dev. environment you want to use is up to you, you can program (write the code) in PSpad and then you can compile it with million different compilers.

To sum it up, there's a standard to which compilers have to (or should) comply. Compilers implement that in whatever way they like and they may add some extra things (like variable size arrays static allocation.) Notice that standard knows nothing about those extensions and therefore doesn't define their behavior.

Then there's a text editor of some kind, in which you write your code and compile it with whatever compiler your heart desires.

C++ is not an easy language to learn unless you have prior experience with lower-level (still high level :)) programming language. There's a lot going on especially if you haven't encountered pointers and references yet.

I suggest you get a new book possibly even containing information on c++0x / c++11 standard which was officially released couple of months ago.

Also, don't use (double)x this kind of typecasting in c++ since it's really a c-way of casting types. Use static_cast < double > (x) in this scenario. (There are other ways to cast too.)

Question

Is it true that C-style strings operations, on average, execute 5 times slower than library string class operations, as C++ Primer, 4th Edition would have me believe?

Why ask?

Because when I actually performance test, it turns out that C-style strings are about 50% faster for a particular example (one used in the book).


Setup

I am reading C++ Primer, 4th Edition, which (on page 138) lists this code:

//  C-style character string implementation
const char *pc = "a very long literal string";
const size_t  len = strlen(pc +1);    //  space to allocate

//  performance test on string allocation and copy
for (size_t ix = 0; ix != 1000000; ++ix) {
    char *pc2 = new char[len + 1];  //  allocate the space
    strcpy(pc2, pc);                //  do the copy
    if (strcmp(pc2, pc))            //  use the new string
        ;    //  do nothing
    delete [] pc2;                  //  free the memory
}

//  string implementation
string str("a very long literal string");

//  performance test on string allocation and copy
for(int ix = 0; ix != 1000000; ++ix) {
    string str2 = str;  //  do the copy, automatically allocated
    if (str != str2)    //  use the new string
        ;   //  do nothing
}    //  str2 is automatically freed

Now bear in mind that I'm aware of that strlen(pc +1) on line 2, and that the first for uses size_t but doesn't subscript the array so it might as well have been int, but this is exactly how it is written down in the book.

When I test this code (with strlen(pc) + 1, which I presume was intended), my results are that the first block executes about 50% faster than the second block, which leads to conclusion that C-style strings are faster than library string class for this particular example.

However, I bet I'm missing something (probably obvious), because of what is written in the book (page 139) relating to the code above:

As it happens, on average, the string class implementation executes considerably faster than the C-style string functions. The relative average execution times on our more than five-year-old PC are as follows:

 user    0.47  # string class 
 user    2.55  # C-style character string

So which one is it? Should I have used a longer string literal? Maybe it was because they used the GNU C Compiler and I used the Microsoft one? Is it because I have a faster computer?

Or is the book just wrong on this one?

Edit

Microsoft (R) 32-bit C/C++ Optimizing Compiler version 16.00.40219.01 for 80x86

Your conclusion that C style strings are faster with this example with your compiler & machine, is almost certainly because – one must presume – you

  • forgot to turn on optimization,
  • forgot to make the string length "unknown" to the compiler (this is tricky) so as to prevent it from optmizing away strlen calls, and
  • forgot and turn off safety range checking (if applicable) which would slow down std::string.

Here's the code I tested with:

#include <assert.h>
#include <iostream>
#include <time.h>
#include <string>
#include <string.h>
using namespace std;

extern void doNothing( char const* );

class StopWatch
{
private:
    clock_t     start_;
    clock_t     end_;
    bool        isRunning_;
public:
    void start()
    {
        assert( !isRunning_ );
        start_ = clock();
        end_ = 0;
        isRunning_ = true;
    }

    void stop()
    {
        if( isRunning_ )
        {
            end_ = clock();
            isRunning_ = false;
        }
    }

    double seconds() const
    {
        return double( end_ - start_ )/CLOCKS_PER_SEC;
    }

    StopWatch(): start_(), end_(), isRunning_() {}
};

inline void testCStr( int const argc, char const* const argv0 )
{
    //  C-style character string implementation
    //const char *pc = "a very long literal string";
    const char *pc = (argc == 10000? argv0 : "a very long literal string");
    //const size_t  len = strlen(pc +1);    //  space to allocate
    const size_t  len = strlen(pc)+1;    //  space to allocate

    //  performance test on string allocation and copy
    for (size_t ix = 0; ix != 1000000; ++ix) {
        char *pc2 = new char[len + 1];  //  allocate the space
        strcpy(pc2, pc);                //  do the copy
        if (strcmp(pc2, pc))            //  use the new string
            //;   //  do nothing
            doNothing( pc2 );
        delete [] pc2;                  //  free the memory
    }
}

inline void testCppStr( int const argc, char const* const argv0 )
{
    //  string implementation
    //string str("a very long literal string");
    string str( argc == 10000? argv0 : "a very long literal string" );

    //  performance test on string allocation and copy
    for(int ix = 0; ix != 1000000; ++ix) {
        string str2 = str;  //  do the copy, automatically allocated
        if (str != str2)    //  use the new string
            //;   //  do nothing
            doNothing( &str2[0] );
    }    //  str2 is automatically freed
}

int main( int argc, char* argv[] )
{
    StopWatch   timer;

    timer.start();  testCStr( argc, argv[0] );  timer.stop();
    cout << "C strings: " << timer.seconds() << " seconds." << endl;

    timer.start();  testCppStr( argc, argv[0] );  timer.stop();
    cout << "C++ strings: " << timer.seconds() << " seconds." << endl;
}

Typical result:

[d:\dev\test]
> g++ foo.cpp doNothing.cpp -O2

[d:\dev\test]
> a
C strings: 0.417 seconds.
C++ strings: 0.084 seconds.

[d:\dev\test]
> a
C strings: 0.398 seconds.
C++ strings: 0.082 seconds.

[d:\dev\test]
> a
C strings: 0.4 seconds.
C++ strings: 0.083 seconds.

[d:\dev\test]
> _

The said, C++ strings are not generally the fastest possible implementation of strings.

Generally, immutable strings (reference counted) beat C++ strings by a good margin, and, surprising to me when I learned that, a string implementation that simply copies the string data is faster still, when it uses an appropriate, fast custom allocator. However, don't ask me how to implement the latter. I only saw the code and test results in another forum, which someone graciously provided after I'd pointed out the general superiority of immutable strings in a discussion with STL and there was some disagreement. ;-)

C++ is a great language (imho).

But starting off with C++ as a completely new language to learn, which formative path would you suggest?

Books, websites, anything that could speed up learning without trading in knowledge and understanding for memorization and confusion. A path indeed, which leads to C++ knowledge and understanding in a structured way.

Is it possible?

I'm asking this question because a friend of mine (php programmer) asked me how to properly (and better) start learning C++.


Edit:

Thanks everybody for your interest and your competent answers. I'm picking up the Phil's one, because in my opinion it very much reflects the ideal of what's gonna be a better approach.

But really thanks everybody for the links, opinions and answers. They're great.

Programming: Principles and Practice Using C++ by Bjarne Stroustrup might be worth checking out, even though (or maybe because) the focus is on programming, not on C++. It doesn't seem to go too deep, though.

When I learned C++ way back when (mid 90's), I used the book C++ from the Ground Up by Herbert Schildt. I found it to be clear and easy to follow and I still refer to it occasionally.

Read the book C++ Primer by Lippman and Lajoie.

Actually do the exercises.

After you get the basics down, I recommend finding a copy of the Ellis and Stroustrup Annotated C++ Reference Manual. It's not up to date with the latest libraries, but it's the only thing I've ever read that gives you an in-depth look at how and why C++ is the way it is. It explains things like how vtables might be laid out in memory, and how that influenced the language design.

I would to point out, again, the new book by Bjarne Stroustrup, Programming: Principles and Practice Using C++, for beginners. Its absolutely great and I wish I had this when I was starting with C++.

I am a beginner in C++. I wanted to know, how internally the function overloading takes place in C++

I recommend you reading C++ Primer. This concept is explained in depth.

On a higher level, function overloading is allowed if both the functions

  • have same name
  • declared in the same scope
  • have different parameter list.

On the lower-level ( inside how compiler figures it out), here's how it is done.

There are 3 steps for function overloading resolution.

e.g void f();   
    void f(int);
    void f(double, double = 3.4);
    void f(char *, char *);

    Function call inside main -> void f(5.6);
  1. Identifies the set of overloaded functions considered for the call, they are called as candidate functions. A candidate function is a function with the same name as the function that is called & for which declaration is visible at the point of call. It also identifies the properties of the argument list in the function call, i.e no of arguments and their types.

    Selected : All 4 functions with name 'f'

  2. Selects the function from the set of candidate functions found in step 1 that can be called with arguments specified in the call. Those are called as viable functions. A viable function is a function that has the same nof of parameters or more parameters ( addn paramters has an associated default argument) than the arguments in the actual function call. Types of arguments must be convertible for the function to be classified as viable.

    Selected : void f(int) and void (double, double =3.4)

  3. Identifies the best viable function among the all viable functions. For (int) conversion need to apply which is a standard conversion (double to int). But for (double, double=3.4), there's a exact match, so no conversion needed. No conversion is better than a conversion.

    Selected : void (double, double = 3.4 )

I have a lot of experience with Java/OO. There are tons of C++ tutorials/references out there, but I was wondering if there are a few key ones that a Java programmer might find useful when making the transition.

I will be moving from server-side J2EE to Windows Visual C++ desktop programming.

I have googled and found tons of resources, but am overwhelmed and don't know where to best spend my time. I have only a few days to get a good start.

Is Visual Studio Express / Microsoft Visual C++ the best IDE for me to start with?

Also, any words of wisdom from others who know and work with both languages?

Visual C++ is a good way to go, you can get the express version for free from here

As far as books It really depends what you want to do. I like the Horton book as far as learning Visual C++, GUI, CLR and Database programming. The Lippman book is a very good tutorial on C++, but it only covers the basic language, which is large.

Once you get past the basics then look at the Meyers books, as stated in other answers.
Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition)

There are a couple of others from this author, they are real good but have not been updated in a long time.

A real good online C++ FAQ is here.

If you put a comment stating what you plan to do with C++, we could give you narrower guidance to point you in the direction you want to go in

The widely recommended books here are Scott Meyers Effective series. "Effective C++", "More Effective C++" and "Effective STL".

I would also recommend the C++ FAQ Lite and The C++ Programming Language.

Here's what I've got. I'm trying to create an instance of Foo within in Bar, using a custom constructor. When I try to call the constructor from Bar's constructor I get and unresolved external.

class Foo
{
public:
    // The custom constructor I want to use.
    Foo(const char*);
};

class Bar
{
public:
    Bar();
    //The instance of Foo I want to use being declared.
    Foo bu(const char*);
};

int main(int argc, char* args[])
{
    return 0;
}

Bar::Bar()
{
    //Trying to call Foo bu's constructor.
    bu("dasf");
}

Foo::Foo(const char* iLoc)
{
}

This is probably what you want:

class Foo
{
public:
    // The custom constructor I want to use.
    Foo(const char*);
};

class Bar
{
public:
    Bar();
   //The instance of Foo I want to use being declared.
   Foo bu; // Member of type Foo
};

int main(int argc, char* args[])
{
    return 0;
}

Bar::Bar() : bu("dasf") // Create instance of type Foo
{
}

Foo::Foo(const char* iLoc)
{
}

As for this declaration: Foo bu(const char*); This is a declaration of a member function named bu which takes a const char* and returns a Foo. The unresolved symbol error is because you never defined the function bu, but you want an instance of Foo not a function.

Other method after seeing comments:

class Foo
{
public:
    // The custom constructor I want to use.
    Foo(const char*);
};

class Bar
{
public:
    Bar();
    ~Bar() { delete bu;} // Delete bu
   //The instance of Foo I want to use being declared.
   Foo *bu; // Member of type Foo
};

int main(int argc, char* args[])
{
    return 0;
}

Bar::Bar() : bu(new Foo("dasf")) // Create instance of type Foo
{
}

Foo::Foo(const char* iLoc)
{
}

And there are also many other problems with your code, maybe getting a book on C++ like C++ Primer would be a good idea.

I'm going to teach the basics of computer programming to a student who wants to learn C/C++, Lua and computer graphics. The books we have available is Programmatic Programmer, Computer Graphics and an old C++ book that I'm replacing since I just bought the C++ Primer book.

Does it matter whether we study GNU C++ or MS Visual Studio C++ if what we want to learn is OpenGL with C/C++ and maybe combined with GLUT if that's still a good idea? I think I know that Silicon Graphics were behind those C libraries some time ago when I studied computer graphics in the nineties.

Do you have any other recommendation how I can teach the student? We reached the point were he can write a simple C/C++ program and compile it with Codeblocks and I previously written my own OpenGL programs with a C compiler from Borland so I can help the student with the theory and the hard work.

So my main question is which compiler we should use? The basic C++ programs we are running work both with the Visual Studio and the GNU C++ compiler in Codeblocks. Do you agree codeblocks is a good environment and better than MS Visual Studio since we still don't have access to the full version of Visual Studio?

Also, the student wants to run linux and therefore I suppose GNU C++ is the best choice so we will use the development environment Microsoft + Linux + Codeblocks + MinGW + OpenGLL dlls(?) and GLUT dlls (?) where I didn't yet get into details with how we can get the last two.

Update

I tested briefly a framework called openframeworks.cc and in the answer here the Microsoft XNA is suggested so we will probably try a little of what we find interesting. Also thanks for the advice of not using GLUT.

Thanks for any pointers and/or advice

If your student is a beginner with code and wants to work with actual graphics, I would highly recommend programming in C# with the Microsoft XNA SDK. Both are completely free to use unless you want to develop commercially.

C# is great because it's almost syntactically identical to Java (i.e. no trash clean-up, no pointers, etc). XNA is also far easier to code with than open GL in every possible aspect (it was designed for indie game development). You can make a simple, pretty-looking 2D game without even dealing with swap chains or anything nasty like that. Easy-to-understand APIs and lots of documentation.

Of course, though, these aren't GNU.

I'm relatively new to C++, I start by reading C++ Primer 4th edition. It has a section explains about Pointers and Typedefs, start with bellowing code.

typedef string *pstring;
const pstring cstr;

I know that after I define typedef string *pstring; I can use *pstring to declare string variable in my code.

*pstring value1; // both of these line are identical,
string value2; // value 1 and value2 are string

The book continue with const pstring cstr1; and *const string cstr2; are identical. I don't understand why they're same declaration?

They are not identical.

 pstring v1;  // declares a pointer to string
 string v2;  // declares an object of type string
 string* v3;  // this is the same type as v1

Just curious to know if anyone has ever used gametutorials.com products for learning directX. I was debating on whether I should buy it or not. I read online that most of his tutorials were written in the source code. It's nice to heavily comment your code but if most of the tutorial is in his code then I don't think that is necessarily the best way to do a tutorial. But anyhow, I am not sure about that, I am just checking for clarification. and checking to see if it would be a good investment.

The problem is that the site is trying to teach you C++ and game programming at the same time. I think trying to do both at the same time is a terrible idea. Game programming is tough, and if you don't know C++ you're just setting yourself up to either fail, or get by with sloppy (and sometimes downright awful) code. So don't do both at the same time: you must learn C++ first, then get into making games. And GameTutorials isn't a resource to help you do that.*


If you don't know C++ yet, do not learn it from any online resource. Books are always a better choice here. I recommend C++ Primer or Accelerated C++. There's a more complete list here.

Both of those costs half as much, and give you a full fleshed-out C++ learning experience. The site I can't speak for, but it doesn't appear to give too fleshed out a tutorial, partly because it keeps mixing it with gaming stuff. You're better off getting tried-and-true books.

If you know C++, then you'd be wasting money on stuff you already know. Get a good Direct3D book. I don't have any modern books on me to recommend, but here's a big list. :) The two (one for DX10, one for DX9) by Luna seem to be good looking, but I don't really know. In any case, a bit more research will tell you what Direct3D book to buy.


*I don't like to speak against things that mean well, but I think the site is really just in a poor position. Teaching C++ and Game Programming shouldn't go hand-in-hand.

So here i am trying to teach my friend the art of C++. He is no newbie to programming, but his area of expertise is somewhat further away from C++. He knows html, php and java fairly well, but it seems this is of no use when it comes to writing a C++ program. We already went through the basics, talked about pointers and such. He even had a course at his university about C++ but he gave up halfway through. It seems that he really understands basic theory - the problem is he fails when it comes to actually using what he knows to write programs.

So what i'm trying to do now is to give him homeworks. The task is always to write a small program, such as a primitive calculator (input two numbers and a letter which determines operation that should be performed...) etc. The idea behind this is to force him to actually use the language to solve problems, debug it and see why it fails and learn from it. But it seems it does not work, since every time i try to make it harder and give him a more complex homework, he is not able to solve it. What should I do now? I'm really running out on ideas of homeworks and i have doubts that this approach is good. Moreover, new semester starts just right now and he has to pass the C++ course this time. So there is even a deadline - the end of this year.

SO, can you help here?

I guess a lot depends on what he is actually having problems with. If he knows Java, I assume he should know the basic concepts of OOP, collections etc., right?

Can he solve the same tasks in Java well? If so, what is it that stops him with C++: lack of understanding of pointers (that can be difficult for many), memory management, destructors, or lack of knowledge about the class library, STL, templates, ...?

You could try sitting through a task with him to see where he has problems, and help him there, step by step.

Back then I really liked Andrew Koenig's Ruminations in C++ - it had a very different take on teaching C++ from the ground up, starting with good, real-world (albeit simple) little programs which actually did something useful, while at the same time teaching the best idioms of the time. Although it is quite outdated by now, sopme of its content might still be useful when adapted to the latest standard.

I would like to befriend you for what you are doing ;-). Anyways, I would first figure out where your friend is getting stuck. Is it in general problem solving or is it with using the C++ language constructs & idioms? Based on your findings you can either direct your friend to improve his problem solving skills or the language skills. If it is the language, I would certainly look into the C++ Primer book by Lippman, Lajoie and Moo and will advise the friend to solve the exercises. Though the book runs to 800+ pages, anyone with prior experience with programming languages & with minimal experience in C++ should be able to read the book within your suggested time line.