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
 

Cromulent

macrumors 604
Oct 2, 2006
6,810
1,100
The Land of Hope and Glory
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.
 

Traith85

macrumors newbie
Dec 29, 2007
2
0
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?
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
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.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
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?
 

sord

macrumors 6502
Jun 16, 2004
352
0
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.