|
|
#1 |
|
Please explain to me...
I just started my university lessons. So, they gave us a book, which explains how are we going to write in c++. The book was written to use a c++ compiler in an PC that runs the free compiler named DevC++ (from Bloodshed software).
But I want to use XCode, so that I don't have to use Virtual PC! So i open xCode and I make a new project (c++ tool) and then I follow my book's instructions which gives me an example hello world application: int main() { cout << "Hello world"; } But XCode gets me an error "cout undeclared"!!! It wants me to write "std::cout" instead! What is going on? Perhaps I am doing something wrong? I just want to program simple console applications using C++ on a mac. How can I do that?
__________________
Oramind: Articles, reviews Techlology and Art
If you don't like it, program it. |
|
|
|
0
|
|
|
#2 | |
|
Quote:
Don't know about either XCode or DevC++, but to understand this you should read about namespaces in your book. This should be written in one of two ways: #include <iostream> int main() { std::cout << "Hello world"; } or: #include <iostream> using namespace std; int main() { cout << "Hello world"; } I'm personally very much against using the second one - it saves typing but makes for lazy programming. I prefer specifying the namespace explicitly, but that's just my preference - whatever you do /never/ use "using namespace" in a header file. |
||
|
|
0
|
|
|
#3 |
|
You need to include iostream.h to make cout available...
Code:
// Hello world program
#include <iostream.h>
int main()
{
cout << "Hello world";
}
![]() EDIT2: Still, "my" simpler example should work just fine, I think namespaces comes much later...
__________________
Those who fail to learn history are doomed to repeat it; those who fail to learn history correctly... why, they are simply doomed. Last edited by Mitthrawnuruodo; Mar 23, 2005 at 05:39 PM. |
|
|
|
0
|
|
|
#4 |
|
so, when using "namespace", you don't have to write "std::" again in the file??
__________________
Oramind: Articles, reviews Techlology and Art
If you don't like it, program it. |
|
|
|
0
|
|
|
#5 | |
|
Quote:
I just looked up Dev-C++ and it's just an IDE that wraps gcc (the GNU C compiler). gcc is also available for OS X, and it's possible that Dev-C++ might work too in an X11 environment on a Mac, but I'll leave it up to someone with a Mac to confirm or deny that. Anyway, if the original program is how it's presented in the book, I'm not very impressed. |
||
|
|
0
|
|
|
#6 | |
|
Quote:
__________________
Those who fail to learn history are doomed to repeat it; those who fail to learn history correctly... why, they are simply doomed. |
||
|
|
0
|
|
|
#7 | |
|
Quote:
|
||
|
|
0
|
|
|
#8 | |
|
Quote:
__________________
Oh, and by the way, Micro$oft suxorz!!! |
||
|
|
0
|
|
|
#9 | |
|
Quote:
![]() Edit: Found a link to the course in English, does this look similar to the course you're taking, Soulstorm...?
__________________
Those who fail to learn history are doomed to repeat it; those who fail to learn history correctly... why, they are simply doomed. Last edited by Mitthrawnuruodo; Mar 23, 2005 at 05:55 PM. |
||
|
|
0
|
|
|
#10 |
|
Guys, the example program in the book does not mention anything about namespaces. It is here that I found this info. However, in my book the program is written
#include <iostream.h> void main() { cout << "hello" } I don't see anything about any namespaces. Another thing I want to ask... Why in the book the main is written "void main()", but in the Mac OS X gcc compiler it is necessary to writte it like "int main()"?? What's the difference? Forgive me, but I am new to C and C++ and I need some info, because the univerities here at greece are completely useless! EDIT: It seems the DevC++ application makes a new file and has namespaces enabled by default!
__________________
Oramind: Articles, reviews Techlology and Art
If you don't like it, program it. Last edited by Soulstorm; Mar 23, 2005 at 05:52 PM. |
|
|
|
0
|
|
|
#11 | |
|
Quote:
|
||
|
|
0
|
|
|
#12 | |
|
Quote:
http://homepages.tesco.net/~J.deBoyn...void-main.html Google is your friend. |
||
|
|
0
|
|
|
#13 | ||
|
Quote:
![]() Quote:
The int indicates that the method will return an int when it's finished...
__________________
Those who fail to learn history are doomed to repeat it; those who fail to learn history correctly... why, they are simply doomed. |
|||
|
|
0
|
|
|
#14 | |
|
Quote:
Thanks, guys!
__________________
Oramind: Articles, reviews Techlology and Art
If you don't like it, program it. |
||
|
|
0
|
|
|
#15 | |
|
Quote:
Ansi standard C++ requires that the main function return an integer. The integer defines the exit status for the application. The pre Ansi standard C++ had no such requirement. xCode is actually using the same compiler as Bloodshed Dev C++. (GCC, although it could be mingw a variation of GCC IIRC) So... My recommendation as a Software Design Engineer is to learn the Ansi C++ is possible.
__________________
iMac 27" i5 Mid 2011 | 1TB HD | 16GB RAM iPhone 4 32 Gig |
||
|
|
0
|
|
|
#16 |
|
By the way... Your book seems like it might be a bit outdated.
__________________
iMac 27" i5 Mid 2011 | 1TB HD | 16GB RAM iPhone 4 32 Gig |
|
|
|
0
|
|
|
#17 | |
|
Quote:
__________________
Oramind: Articles, reviews Techlology and Art
If you don't like it, program it. |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Can someone please explain to me why they're referred to as GSM and CDMA... | zorahk | iPhone | 34 | Feb 15, 2011 08:47 AM |
| Mac Mini 2010 - Can someone please explain to me how to get 5.1 surround via HDMI? | Baron Aloha | Mac mini | 12 | Jul 16, 2010 04:40 AM |
| Could someone please explain to me what exactly I need to do? | BaLaClavaAa | Jailbreaks and iOS Hacks | 5 | May 1, 2009 06:28 PM |
| Please explain to me... No2 | Soulstorm | Mac Programming | 12 | Sep 9, 2005 11:04 AM |
| Please explain to me... | mymemory | General Mac Discussion | 20 | May 6, 2002 05:13 PM |
All times are GMT -5. The time now is 03:55 AM.









Linear Mode

