C/C++ Learn C++ Programming with Comprehensive Documentation

  • Thread starter Thread starter soul
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
Learning C++ requires familiarity with its standard library and functions, which can be acquired through experience and comprehensive documentation. Resources like C++ Reference and books such as "Accelerated C++" and "The C++ Standard Library: A Tutorial and Reference" are recommended for understanding modern C++ features. C is a subset of C++, meaning well-written C code generally compiles in C++, but C++ offers easier and more efficient programming methods. While C-style techniques may be familiar, they can lead to complications in C++. Utilizing libraries like Boost can enhance C++ programming by addressing common issues with string handling and compatibility.
soul
Messages
61
Reaction score
0
Hi,

I have started programming with java and now I am trying to learn C++ by myself. What a real problem for me is that I don't know which methods I am going to use for a specific problem. Is there any documentation or API that I can use for C++.
For instance this;

#include <iostream>
using namespace std;
int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
}

How did we know that we should use iostream and cin, cout stuff.
 
Last edited:
Technology news on Phys.org
soul said:
Hi,

I have started programming with java and now I am trying to learn C++ by myself. What a real problem for me is that I don't know which methods I am going to use for a specific problem. Is there any documentation or API that I can use for C++.
For instance this;

#include <iostream>
using namespace std;
int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
}

How did we know that we should use iostream and cin, cout stuff.

You figure out which functions (they really are called functions in C++, not methods) to use principally through experience and reading. The C++ standard library and standard template library are extremely well documented. For instance, C++ Reference is pretty helpful site.

Alternatively, you could learn about this kind of thing from a book. A decent way to start would be to pick up an introductory C++ book like Deitel's C++: How to Program, which contains a good account of the standard library as well as a discussion of the language more generally.

Of course, if you're really serious about understanding the standard library, the canonical book is The C++ Standard Library: A Tutorial and Reference. It's a bit pricey (as is the Deitel book) but it's something every C++ programmer will benefit from reading.
 
Thank you Shoehorn!
I hope I can reach the point that I want in C++ with your help.:)
 
The Deitel book is popular, but it was first written back in the 1990s, before the current C++ standard and standard library were established. I don't remember which edition I looked at most recently, but it was definitely several years after the C++ standard, and it struck me as being rather old-fashioned with respect to the modern features of the standard library. For example, it taught text manipulation first using plain old character arrays and pointers, and "tacked on" a later chapter about the standard library's "string" data type which is much easier to use correctly IMO. Similarly it favored C-style arrays in general, with the modern container data types such as vectors left until the end of the book, with a very superficial treatment.

For a modern approach to C++ that starts out using the standard library as much as possible from the beginning, you might consider Koenig and Moo's https://www.amazon.com/dp/020170353X/?tag=pfamazon01-20, which is a rather slim volume and not super expensive.
 
Last edited by a moderator:
By the way, I wonder the similarities between C and C++. If I learn C++, will I be able to code with C? Are they similar?
 
jtbell said:
The Deitel book is popular, but it was first written back in the 1990s, before the current C++ standard and standard library were established. I don't remember which edition I looked at most recently, but it was definitely several years after the C++ standard, and it struck me as being rather old-fashioned with respect to the modern features of the standard library. For example, it taught text manipulation first using plain old character arrays and pointers, and "tacked on" a later chapter about the standard library's "string" data type which is much easier to use correctly IMO. Similarly it favored C-style arrays in general, with the modern container data types such as vectors left until the end of the book, with a very superficial treatment.

These are indeed valid criticisms. He's got rather an idiosyncratic style and many of his techniques in teaching C++ seem to favour approaches that would be more at home in C. He's also tends to be slightly too verbose when discussing examples.

Nonetheless, it's a clear, well presented book and is worth a read in my opinion.

jtbell said:
For a modern approach to C++ that starts out using the standard library as much as possible from the beginning, you might consider Koenig and Moo's https://www.amazon.com/dp/020170353X/?tag=pfamazon01-20, which is a rather slim volume and not super expensive.

Yup. I should probably have mentioned this in preference to Deitel. Accelerated C++ really is a great book from which to learn C++.

soul said:
By the way, I wonder the similarities between C and C++. If I learn C++, will I be able to code with C? Are they similar?

C is a subset of C++. Generally speaking, this means that any well written C code should compile under any good C++ compiler. The converse, however, is not true.

More precisely, C++ is easier to learn and easier to write than C. In fact, unless you have a very specific reason for wanting to learn C (like, say, a burning desire to program microcontrollers), I'd go so far as to say that you're better off not learning C before learning C++. Unfortunately, several methods and techniques that are commonly used by C programmers will get you into a whole lot of trouble if you attempt to use them in C++.
 
Last edited by a moderator:
shoehorn said:
[Deitel]'s got rather an idiosyncratic style and many of his techniques in teaching C++ seem to favour approaches that would be more at home in C.

I suspect that "C++ How to Program" was derived from his earlier "C How to Program."

C is a subset of C++. Generally speaking, this means that any well written C code should compile under any good C++ compiler. The converse, however, is not true.

More precisely, C++ is easier to learn and easier to write than C.

To elaborate on this: For some things (two examples are terminal and file input/output, and text manipulation), C++ has two ways of doing them: a "C style" way which is inherited from C, and a "C++ style" way which is new. Bjarne Stroustrup (the original creator of C++) included the "C style" methods mainly for backward compatibility with C. His idea was that people could thereby easily migrate their existing C code to C++, while using the "C++ style" methods in new code.

In my opinion, the "C++ style" ways usually are easier to learn, and to use in many situations. Not all... in particular, creating nicely-formatted output using C++ iostream member functions can be very tedious, as opposed to C's concise format descriptors.

But I'd never use C-style character arrays and char* pointers for text, instead of C++'s 'string' data type, or C-style arrays instead of C++'s vectors, etc., except perhaps if I were in a situation where every last bit of efficiency was absolutely essential.
 
But I'd never use C-style character arrays and char* pointers for text, instead of C++'s 'string' data type
Except where you need to talk to other libraries. One problem with C++ brilliant idea of leaving the CString class as 'an exercise for the student' for the first 10years of the standard is that every gui toolkit, library and OS call has their own string type and generally the only common way between them is char*.
 
mgb_phys said:
Except where you need to talk to other libraries. One problem with C++ brilliant idea of leaving the CString class as 'an exercise for the student' for the first 10years of the standard is that every gui toolkit, library and OS call has their own string type and generally the only common way between them is char*.

This is one example (among many others) of why it's a good idea to use the Boost libraries. They really are superb.
 
  • #10
mgb_phys said:
One problem with C++ brilliant idea of leaving the CString class as 'an exercise for the student' for the first 10years of the standard

<nitpick>

There was no C++ standard until 1998, and that standard included string, vector, etc.

</nitpick>

OK, one can argue that there was a "de facto standard" defined by the earlier editions of Stroustrup's "The C++ Programming Language." There was another book, with "Annotated" in the title, but I can't remember the rest of it.
 
  • #11
There wasn't an 'ISO' C++ standard until 1998 - but the C++ programming language came out in 1985 and the C++ARM in 1990. They could have at least suggested a structure for the string lib.
Even the string class in the std lib isn't a great design, so many people use either the STL or boost ones instead, making it even worse.

Windows is the worst offender with you needing char*, MFC CString, BSTR and the same again for unicode and others in the same program.
 
  • #12
mgb_phys said:
Even the string class in the std lib isn't a great design, so many people use either the STL or boost ones instead

Didn't std::string come from the STL?
 
Back
Top