Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BrendanSJCI

macrumors newbie
Original poster
Oct 24, 2006
4
0
I downloaded the newest version of xtools so I could follow along in a book about C++. The last time I did anything in the book was over 5 years ago, and my dad just set up the software I needed to do the examples in it.

I made a blank C++ document, and it asked if I wanted to make a corresponding ".h" file, which I declined. Is this where the definitions for certain functions are stored? If so, is that the file I should refer to in my headers? The book says, for example, Borland C++ uses IOSTREAM.H for stream-related definitions, while Microsoft Visual C++ uses other headers in addition to that; how does it work in xcode?

In addition to not knowing that, I'm not really sure how to test the code that I'm putting in. I get the general idea of the targets, but I don't know which to choose or how to set them up.

If anyone could guide me through setting up xcode to let me work through this book that would be a great.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
BrendanSJCI said:
I downloaded the newest version of xtools so I could follow along in a book about C++. The last time I did anything in the book was over 5 years ago, and my dad just set up the software I needed to do the examples in it.

I made a blank C++ document, and it asked if I wanted to make a corresponding ".h" file, which I declined. Is this where the definitions for certain functions are stored? If so, is that the file I should refer to in my headers? The book says, for example, Borland C++ uses IOSTREAM.H for stream-related definitions, while Microsoft Visual C++ uses other headers in addition to that; how does it work in xcode?

In addition to not knowing that, I'm not really sure how to test the code that I'm putting in. I get the general idea of the targets, but I don't know which to choose or how to set them up.

If anyone could guide me through setting up xcode to let me work through this book that would be a great.

For beginners, best to start with "New Project", then in the assistant scroll down to "C++ tool". That produces a complete program that doesn't do much, press Command-R to run it, then you can start adding things.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
There should be made a stickie about C++ and Xcode because this gets asked a few times a week...
 

BrendanSJCI

macrumors newbie
Original poster
Oct 24, 2006
4
0
Thanks for the help getting running. Sorry for asking a common question, but a search for "C++" didn't turn up anything.

The book I'm using is from 1994 so I've had to change some things around. This bit of code is giving me two errors that I can't figure out;

#include <iostream>

using namespace std;

int main(int)
{
int number = 1001;

cout << "Decimal: " << number << "\tHexidecimal: " << hex << number << endl;

cout << "Decimal: " << dec << number << "\tOctal: " << oct << number << endl;
}

the errors are:
"'number' was not declared in this scope"
"expected ';' before 'std'"

Could some one clear this up for me?
 

YoNeX

macrumors regular
Apr 29, 2005
141
0
BrendanSJCI said:
Thanks for the help getting running. Sorry for asking a common question, but a search for "C++" didn't turn up anything.

The book I'm using is from 1994 so I've had to change some things around. This bit of code is giving me two errors that I can't figure out;

#include <iostream>

using namespace std;

int main(int)
{
int number = 1001;

cout << "Decimal: " << number << "\tHexidecimal: " << hex << number << endl;

cout << "Decimal: " << dec << number << "\tOctal: " << oct << number << endl;
}

the errors are:
"'number' was not declared in this scope"
"expected ';' before 'std'"

Could some one clear this up for me?

What values does oct, dec, and hex have. They don't seem to be declared and/or intialized.
 

BrendanSJCI

macrumors newbie
Original poster
Oct 24, 2006
4
0
From what I understand, they manipulate the number so as to display it in hexidecimal, octal, and decimal. The next example does the same thing but uses setbase() and <iomanip>. That program has errors too, which I suspect are from me trying to translate from a pre-asni/iso book. I'm thinking of getting a new book so I can focus on what they're trying to show me rather than tracking down bugs.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
BrendanSJCI said:
Thanks for the help getting running. Sorry for asking a common question, but a search for "C++" didn't turn up anything.

The book I'm using is from 1994 so I've had to change some things around. This bit of code is giving me two errors that I can't figure out;

#include <iostream>

using namespace std;

int main(int)
{
int number = 1001;

cout << "Decimal: " << number << "\tHexidecimal: " << hex << number << endl;

cout << "Decimal: " << dec << number << "\tOctal: " << oct << number << endl;
}

the errors are:
"'number' was not declared in this scope"
"expected ';' before 'std'"

Could some one clear this up for me?

I recommend getting rid of "using namespace std" and using std::cout, std::dec and so on. The cost of typing five characters is minimal compared to the cost of having to figure out what your code means. And you don't run into nasty surprises if you add another variable like "int hex = 0x1234;" in your program.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.