Apple’s Worldwide Developers Conference to kick off June 10 at 10 a.m. PDT with Keynote address

The Keynote will be available to stream on apple.com, the Apple Developer app, the Apple TV app, and the Apple YouTube channel. On-demand playback will be available after the conclusion of the stream.

Developer Forums relocated!

Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

What function do I use in Xcode?

Hello I am starting some lessons on C++

I use an Apple Computer

IMac desktop



Problem is last simple program I got to work on my old Windows computer

when i run it i got the 2nd window to pop up.



When I run it on my MAC using Xcode. When i run and build

i get message of "build succeeded" which is good

but no second screen of the program working



here is the actual code



Ok Now I got Xcode to work.



I am not able to get the separate screen to work when i run a simple program.



So here is my program just a Helloworld program



[CODE]

#include <iostream.h>







int main()



{

int mynumber;

mynumber = 34

cout << " my number is ";

cout << "Hello world!" << endl;

cout << mynumber;

system("pause");

return 0;



}



[/CODE]

So when i run it in Xcode, it works. it says build Succeeded

however i am supposed to get a second pop screen like a command prompt, like same when i run program on my Windows computer

that has "hello world" and 34 etc.



What function on Xcode do i use to make this happen?

thanks

IMAC, new IMAC

Posted on Nov 3, 2011 10:52 AM

Reply
Question marked as Best reply

Posted on Nov 3, 2011 12:01 PM

You have to open the console to see the output. In Xcode 4 choose View > Debug Area > Show Debug Area. In Xcode 3 choose Run > Console.

11 replies

Nov 3, 2011 2:21 PM in response to Mark Szymczyk

Ok that is a start. WHat i need is to how to be able to see the main output.


I am supposed to get a second screen to pop up after i hit run. with the main output on it.


eg.


my number is .. Hit any key to continue


i was told with Apple i am supposed to use Command line?


What do you suggest?


What am i saYING is how to compile the whole thing.


Thanks

Nov 3, 2011 4:49 PM in response to worldtraveller321

Ok here is what i have done next. I follow some instructions online and was able to get c++ to work and compile from xcode

but it only works in a different format.


this is what I have put in it that works in Xcode


"

#include <stdio.h>


int main (int argc, const char * argv[])

{


// insert code here...

printf("this is my first project\n");


return 0;

}


"


And I get it to work. But how come it only works with the line as "printf"?

as the proper way to write that line is this

"

#include <stdio.h>


int main (int argc, const char * argv[])

{


// insert code here...

cout <<"this is my first project");


return 0;

}


So when i try to run it this way , it does not work and i get error in my lines.

but this format works in Windows using the Dev C++ etc.


So what can you say? do i have to change the formats for Apple?

thanks

Nov 3, 2011 5:50 PM in response to worldtraveller321

The printf works because stdio.h defines printf. The cout doesn't work because iostream.h defines cout, not stdio.h. You have to include iostream.h. You also have to put std:: before the call to cout or define a namespace so you don't have to add std::. If you read the article I linked to in my last answer, create a project, and look at the main.cpp file, you will see what you have to do to make cout work.

Nov 4, 2011 2:48 AM in response to Mark Szymczyk

Hello again. I like to clarify this as i am confused


for when writing out a C++ program in both platforms of Windows and MAC (Apple)


To run the program.


Is my code going to be automatically different in order to run the program on my MAC

vs what you have to write for the Windows platform?


or should it all be the same, with just a few odd things changed.

thanks


Could anyone out there find me a Youtube video

to show me exactly what i have to do.

this is making my head spin

thanks for all your help guys

Nov 4, 2011 11:00 AM in response to Mark Szymczyk

Ok all I need your help. What is wrong with this program. I am trying to run it in Xcode.



But it says I have errors. Yet this works in Windows.



[code]#include <iostream>





int main()

{

using namespace std;

int mynumber;

mynumber = 20;

mynumber = mynumber +6;

cout << "hey there mr jones.";

cout << "what is this number";

cout << mynumber;

cout << "Hello world! " << endl;

cout << " my best number is ";

cout << mynumber;

mynumber = mynumber +54;

cout << " my other number is ";

cout << mynumber;

system("pause");

return 0;

}

[/code]



It keeps pointing at "#include <iostream>"



So i am not sure.



Can someone show me a simple program that would work in Xcode4 that would work.

please i just need something small to work from and figure out my errors as i am just starting on this

thanks

Nov 4, 2011 1:41 PM in response to Mark Szymczyk

Ok i was able to get it working


Here is my code

#include <iostream>


usingnamespacestd;


int main() {

int number1 = 1;

int number2 = 2;

int add;

cout<<"enter the first number\n";

cout<<"enter the second number\n";

add=number1+number2;

cout << "the total is"<<add<<endl;

cout << "hello world" << endl;

cout << " hey there mr jones " << endl;

}


and it works in Xcode4

thanks everyone

What function do I use in Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.