.
Write C++ Program Using Xcode
Write C++ Program Using Xcode
1) Run Xcode
(this tutorial uses Xcode version 4.6)
2) Create a new project.
Go to Menu. Select File/New/Project/
3) Select template.
Select Application/Command Line Tool.
4) Set options for the project.
Click Next to create project folder. Click Create to confirm your folder location.
Done.
5) Edit the codes.
Click the file name main.cpp and edit the codes in the code editor.
By default, you are given the Hello World codes.
6) Run the codes.
The Output Window displays the outcome.
7) Input values for c++ program in xcode
Try adding input statement for integer value.
//
// main.cpp
// mycpp
//
// Created by mymacmini on 8/23/16.
// Copyright (c) 2016 razoph. All rights reserved.
//
#include <iostream>
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Enter a number \n";
int number;
std::cin>>number;
std::cout<<"You have entered "<<number;
return 0;
}
|
Run the program.
Enter 123.
Press [SHIFT]+[RETURN] Key. (Refer http://stackoverflow.com/questions/6481943/xcode-4-console-wont-take-user-input )
8) Finding the executable file.
Select the the mycpp project/Products/mycpp/Show in Finder.
Double-click the executable file mycpp.
A console window will popup and execute the program.
Enter 123 and press [RETURN] key.
You should get the expected outcome.
No comments:
Post a Comment