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

ktalebian

macrumors regular
Original poster
Dec 25, 2007
214
0
Hi
I have installed Xcode 3 on my Mac OS X 10.5.1, and i want to use it to program C++. But the problem is that I really don't know how!
I went to start a new project, and selected Carbon C++ Standard.
Then I added a cpp file to it, and used the very simple code:

#include <iostream>

int main(void)
{
cout << "Hello World!";
return 0;
}


but it did not compile! Why?
THanks
 
Hi
I have installed Xcode 3 on my Mac OS X 10.5.1, and i want to use it to program C++. But the problem is that I really don't know how!
I went to start a new project, and selected Carbon C++ Standard.
Then I added a cpp file to it, and used the very simple code:

#include <iostream>

int main(void)
{
cout << "Hello World!";
return 0;
}


but it did not compile! Why?
THanks

Choose a C++ Tool project from the Command Line Utility section in the new project menu.
 
Same Problem, but with C instead of C++

I'm also in almost the same situation - using Xcode version 3.0 on OS X 10.5.1, but am trying to compile the "hello world!" example code by starting a new project and choosing "external build system" under the Dynamic Library project category. The code I'm using is:

#include <stdio.h>

int main (int argc, const char * argv[])
{
printf("Hello, World!\n");
return 0;
}


My problem is that it debugs and runs without error, but there is no output on the screen. The only way that I can get a result is by accessing the Console under the "Run" menu, which does display the output. I'm also completely new to programming and trying to get a feel for the tools - is this normal or should there be an output screen that pops up once I compile? Any advice?
 
I'm also in almost the same situation - using Xcode version 3.0 on OS X 10.5.1, but am trying to compile the "hello world!" example code by starting a new project and choosing "external build system" under the Dynamic Library project category. The code I'm using is:

#include <stdio.h>

int main (int argc, const char * argv[])
{
printf("Hello, World!\n");
return 0;
}


My problem is that it debugs and runs without error, but there is no output on the screen. The only way that I can get a result is by accessing the Console under the "Run" menu, which does display the output. I'm also completely new to programming and trying to get a feel for the tools - is this normal or should there be an output screen that pops up once I compile? Any advice?
This is normal. I just keep the console visible at all times.
 
Hi
I have installed Xcode 3 on my Mac OS X 10.5.1, and i want to use it to program C++. But the problem is that I really don't know how!
I went to start a new project, and selected Carbon C++ Standard.
Then I added a cpp file to it, and used the very simple code:

#include <iostream>

int main(void)
{
cout << "Hello World!";
return 0;
}


but it did not compile! Why?
THanks

Because you got something wrong.

Now if you want us to tell you what you got wrong, what about telling us whether the compiler gave you any error messages, and if it did, which ones it gave?
 
Because you got something wrong.

Now if you want us to tell you what you got wrong, what about telling us whether the compiler gave you any error messages, and if it did, which ones it gave?

Looking at your code, you have 1 problem, with 3 ways to fix
Problem: cout is in the std namespace, which you haven't referenced.
Solutions:
  • Add "using namespace std;" under your #include (worst option)
  • Add "using std::cout;" under your #include (best option)
  • Change your cout to std::cout (only decent if you are only going to use it once or twice)

Also its better practice to have your main be "int main(int argc, char *argv[])" instead of "int main(void)"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.