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

Recoverytwo

macrumors newbie
Original poster
Feb 3, 2011
3
0
I just started programing C++ and I am just trying to do the "Hello World" program and it wont compile (I am using Xcode), here is what I read to put in.


#include <iostream>

int main()
{
std::cout << "hellow world \n";
return 0 ;
}

I get back "Iostream: no such file in directory" and "Expected expression before ":" token.

Can someone please help ?
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
You may want to step back and learn how to use the compiler without Xcode first.

Your code works fine, so it is something about the way you created your Xcode project that is causing the problem.

EDIT: Borrowing from https://forums.macrumors.com/threads/1078777/

Open Terminal.app

Code:
cd ~/Documents
echo "#include <iostream>

int main() 
{
std::cout << \"hellow world \n\";
return 0 ; 
}" > myHello.cpp
g++ myHello.cpp
./a.out

Works fine. Substitute an editor for the file creation via echo if you want something a bit easier to work with.

B
 
Last edited:

Recoverytwo

macrumors newbie
Original poster
Feb 3, 2011
3
0
Maybe it's because you misspelled hello? ;)

By George you've got it !

I opened it up and used the objective-C class template in the iOS group, I didn't notice what i did before I started, is there any template I can use that will use C++ in iOS ?
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
By George you've got it !

I opened it up and used the objective-C class template in the iOS group, I didn't notice what i did before I started, is there any template I can use that will use C++ in iOS ?

If you are learning (and especially if you are learning C++ as your first language) then stick to Mac stuff for the time being. Writing iOS or Mac Cocoa apps that make use of C++ requires some knowledge of C++, Objective-C and Objective-C++. It is not going to help you.

For the first few months most beginners just stick to writing command line applications, the GUI stuff will come later once you have started to feel comfortable with the programming language.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
This does raise the question. If your goal is iOS development, why are you learning C++ first?

You could at least be using Foundation classes in Objective-C to do the same thing as Kochan does in his book.

Are you following a particular book or course?

B
 

Recoverytwo

macrumors newbie
Original poster
Feb 3, 2011
3
0
I am using "Sams Teach Yourself C++" I had tried to program C++ a few times before but got distracted by things.

So you would suggest Objective C as a first programing language ?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I am using "Sams Teach Yourself C++" I had tried to program C++ a few times before but got distracted by things.

So you would suggest Objective C as a first programing language ?

Why not? If your goal is to learn Objective-C and Cocoa Touch, learning another C-related, Object-Oriented language seems like a suboptimal approach. Learning is always good, and you can use C++ in Objective-C (called Objective-C++), so it's not terrible by any means, but you will need to learn Objective-C to interact with the frameworks needed to make iOS applications. Why not start there? I don't think C++ is easier to learn than Objective-C, so that's not a compelling reason to do C++ first.

-Lee
 

Blakeasd

macrumors 6502a
Dec 29, 2009
643
0
IOS does not have any C++ templates. If you plan to develop for IOS then I would suggest learning Objective-C first.
 

chrono1081

macrumors G3
Jan 26, 2008
8,453
4,151
Isla Nublar
+1 for Objective-C first.

C++ has a lot of gotchas and rotten things in it. It also takes forever to make something useful using it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.