PDA

View Full Version : New to programming, need help setting up for C++ in xcode




BrendanSJCI
Oct 24, 2006, 11:49 AM
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
Oct 24, 2006, 12:18 PM
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
Oct 24, 2006, 01:25 PM
There should be made a stickie about C++ and Xcode because this gets asked a few times a week...

BrendanSJCI
Oct 25, 2006, 12:35 PM
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
Oct 25, 2006, 04:24 PM
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
Oct 25, 2006, 10:54 PM
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
Oct 26, 2006, 02:41 AM
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.

BrendanSJCI
Oct 26, 2006, 09:34 PM
Thanks, getting rid of "using namespace std" fixed it.