XCode compiler for mac and books

Pages: 12
I'm a totally new programer (just started yesterday), and I was working through the c plus plus manual here: http://www.cplusplus.com/files/tutorial.pdf and it works fine. However, when I tried to find other books to supplement my knowledge, most of them turned out to not be compatible with XCode gcc or ccc+ compiler for mac and then produced errors.

For example, I tried to put in the code of the book here: http://www.angelfire.com/art2/ebooks/teachyourselfcplusplusin21days.pdf.

When I typed in the code at page 16-17, it produces errors, like it says that it couldn't find the file iostream.h, but it works fine with only "iostream". On another book, the XCode compiler could not interpret the word "void" at the start.
Hi,

In modern C++, we use #include <iostream> , not #include <iostream.h>
Also, by this :
the XCode compiler could not interpret the word "void" at the start.


do you mean void main() ?

It should be int main()

Hope this helps :+)

Edit:

Be wary of books - some of them are shockingly bad, instead get one from one of the pillars of the industry - Stroustrup, Herb Sutter.
Last edited on
I think that I figured out that we have to use iostream, not iostream.h. However, the book did not give any warning of that! (that's from the teach yourself c++ in 21 days) The void main came from another book, and again there was no warning! (I know that int main works, but why did the book use void main)?

May I continue to use this thread to ask further questions?

Thank you so much - did not expect this forum to be that supportive of newbies, I thought this was only for professional programmers.

But are all of the formulas of the Stroustrup and Herb Sutter books compatible with the modern C++ and compilers of XCode such as gcc and ccc+ (sorry if I'm mixing up stuff, I just started yesterday)
By the way, I opened that cartoon: http://abstrusegoose.com/249

It doesn't say anything bad about the book - the character actually finishes the book in 21 days then just wastes the other days doing recreational programming and studying subjects unrelated to programming to make a potion or something?
May I continue to use this thread to ask further questions?


Sure, that is what we are all here to do. There are lots of experts still willing to help anyone.

.... and again there was no warning! .....


Yes, I wouldn't bother with such a book if that is what they are saying. that why I would recommend a book by Stroustrup (The inventor of C++, and much involved in the decades since then). Programming Principles is probably the one you are after - check on his website though.

But are all of the formulas of the Stroustrup and Herb Sutter books compatible with the modern C++ and compilers of XCode such as gcc and ccc+ (sorry if I'm mixing up stuff, I just started yesterday)


Yes.

It doesn't say anything bad about the book - the character actually finishes the book in 21 days .....


The point of the cartoon is that it is ridiculous to claim to have learnt C++ in 21 days - it's bit like saying one can be a nuclear physicist in 21 days ;+) Also, those things aren't unrelated to programming - developers are always doing projects about all kinds of different things, and it is helpful to have some domain knowledge of what it is the software is about.

.... but why did the book use void main


That was actually legal C code way back in the dim past of circa 1985, I am mystified as to why anyone would still have that. That is why one should avoid such books / websites. One thing that happens, is in India the Education Board actually specifies that students use the Borland C++ v3.0 IDE - which is at least 25 years out of date, and it accepts void main() , so we still see people post code with that in it.

Also, check out the Tutorials, Reference & Articles at the top left of this page.
Yeah, I'm using the "official" cplusplus tutorial here: http://www.cplusplus.com/files/tutorial.pdf

Is this what you are referring to: http://www.stroustrup.com/programming.html

I'm currently using "The C++ Programming Language" by Stroustrup

Should I do the Programming Principles after finishing "The C++ Programming Language", or is Programming Principles basic and should be read before "The C++ Programming Langugae"?
Last edited on
Hi

The Programming Principles is the introductory text book, so you should start with that. The other is more of a reference and has details of the C++11 standard - which is probably way too much for a beginner. However great to have once you have gone past the beginner stage.
Okay thank you! I'll read that.

Should I finish the official tutorial here: http://www.cplusplus.com/files/tutorial.pdf first?

What is simply wrong with most book that make them incompatible with the XCode compilers? Are they simply outdated or is XCode simply too new? Will the tutorial here: http://www.cplusplus.com/files/tutorial.pdf and the programming principles BOTH be compatible with XCode's gcc and ccc+ compilers?

I know that you gave me a link to a comic about learning how to program in a short time. Is 1 hour a day for 9 months usually enough to give me a sufficient knowledge on how to program and encode the common algorithms?
Last edited on
Should I finish the official tutorial here


I am fairly sure Stroustrup's book will take you through from the very beginning, I mentioned the Reference, Tutorial and Articles sections on this site as an additional material to look at. The reference section is good for looking at individual functions etc to see how they work.

What is simply wrong with most book that make them incompatible with the XCode compilers?


It may not be because they are outdated or anything, the problems you describe would be encountered by almost anyone writing some code, using almost any compiler. The thing is that they are just poorly written in general. I guess the main one would the sheer naivety of how they write code, and general bad practice.

Will the tutorial here: http://www.cplusplus.com/files/tutorial.pdf and the programming principles BOTH be compatible with XCode's gcc and ccc+ compilers?


Yes, the code examples should work just fine.

Stroustrup does have his own std lib facilities header, which apparently just has a subset of the real thing, so obviously the code that comes from that won't be standard. However I am sure this is all explained thoroughly in the Book, and it won't harm your education to follow it.

Is 1 hour a day for 9 months usually enough to give me a sufficient knowledge on how to program and encode the common algorithms?


Well coding is like anything else - the more practice you have, the better you will probably be. But it is obviously going to depend on how much you can remember, how much you might forget, how well you can understand the connections between things, how well you can apply something you have learnt to something else, what your best mode of learning is (actually doing it is best for most people, but different people learn best in different ways or a mixture thereof), and a bunch of other factors as well. And it's not just the language, there are other things such as design patterns, best practice ways of coding, all sort of clever techniques to do things well.

Beware that C++ is actually quite a big topic - some things that might seem to be pretty easy at first glance, can be quite involved in practice. For example, a class is a way of storing data and the functions that operate on that data into 1 concept. But in practice designing the best way of how multiple classes interact with each other is often not trivial at all.

And C++ is such a big topic - I reckon one could spend their entire working life doing C++, and not run out of things to learn - or things to do.

In terms of encoding common algorithms, C++ comes with a thing called the Standard Template Library (STL) which is a collection of classes, functions, containers, algorithms and uses Templates to tie them all together. So it won't be a case of having to encode algorithms, it's a case of learning how to use them.

Having said that, teachers at school or Uni often get students to write their own algorithms and data structures, so they learn in detail how these things work. So a student might be asked to write their own code to sort something, or implement a linked list for example, even though std::sort and std::list<> already exist in the STL.

Last edited on
Hmmm... I was talking about the people who use void in their book and the ones with a .h. Why do they still include those?



"Stroustrup does have his own std lib facilities header, which apparently just has a subset of the real thing, so obviously the code that comes from that won't be standard. However I am sure this is all explained thoroughly in the Book, and it won't harm your education to follow it."

what do you mean?
- does this mean that this book is not a good idea for learning at the start since the code there is nonstandard, or is the deviation very minor?

also, would you recommend going to the tutorial here: http://www.cplusplus.com/files/tutorial.pdf , or go straight to the whole book, since I have limited time.
How about the code in c++ for dummies? It also gives errors in compiling. (that's where I learned the void)
I don't get it. See the picture when I copy paste the hello world program into the compiler

https://www.dropbox.com/s/lhd9i2p53j3s402/Screen%20Shot%202015-08-01%20at%205.50.45%20PM.png?dl=0

why did that happen?

If ever, how do I install this: http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h into xcode (I'm using a mac).

Is the tutorial here: http://www.cplusplus.com/files/tutorial.pdf enough? Even if I change the first line of the one in Stroustrup's book to the iostream, it still does not work.
Last edited on
- does this mean that this book is not a good idea for learning at the start since the code there is nonstandard, or is the deviation very minor?


No, go with Stroustrup's book.

How about the code in c++ for dummies?


No keep away from those books.

why did that happen?


Are you sure you read the instructions properly? For that code to work you must have the std_lib_facilities.h file in the same directory as the code you are compiling, or somewhere else that the IDE can find it. I am sure this concept should have been explained clearly in the book. AFAIK the book should come with a CD with necessary files on it. And your IDE says on the left that the file was not found.


Hmmm... I was talking about the people who use void in their book and the ones with a .h. Why do they still include those?


C++ is language that has always evolved - bad authors still have them for some unknown reason.
yes, how do I put that file in the same directory? I don't get it... Do you know how to do it? i'm using a macbook
Doesn't the book explain what to do?

Have you got the CD that comes with the book, or can you download the file?


I downloaded the file but here is yet another error.
https://www.dropbox.com/s/bd0rxvlybivg6yw/pic2.png?dl=0

I cannot find any other instruction in the book regarding that

since there are a lot of issues and stuff, would I be better off just reading the http://www.cplusplus.com/files/tutorial.pdf
Last edited on
Oh well, there must a problem with that file. That file is supposed to be only used for a short time, maybe you can do your code in a normal fashion:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>  // header file contains definitions for input output like std::cout
                               // system header files use the <> and no file extension
                               // user defined header files use "" quotes and do have a file extension, and can have a full or relative path
                               // if no path info, the compiler looks in the current directory for the header file
                               // if not found there is a set rules about where the compiler will look
                               // eg #include "MyHeader.hpp" // hpp means a header file with cpp code inside

int main() {  // start of the main function - return type is int function definition is contained between braces

     std::cout << "Hello World! \n" ;  // Prints text to the screen 
                                                   // cout is part of the std namespace 

return 0;  // returns a 0 to the operating system - indicates program ran successfully - other values indicate a problem of some kind
}  //end of main function and end of program 

but then how would I use the remainder of the book if I won't use the same header as that book?

Would it be enough to do the tutorial file: http://www.cplusplus.com/files/tutorial.pdf in the interest of time since I have a lot of issues with the book?
It's not the remainder of the book, it's only for a short time. You shouldn't have a lot of issues once you get going - you can always ask here for help.

The tutorial is a description about different aspects of c++ , it doesn't ask you questions or make you do exercises to ensure you have learnt properly, so no I don't think that reading the tutorial will be anything near as good.
Pages: 12