C++ Compiler for mac.

Started by
26 comments, last by igni ferroque 18 years, 10 months ago
Quote:Original post by ApochPiQ
...in C++, it is preferred to use std::cout::endl rather than '\n' or similar escape sequences. endl is more portable and guaranteed to produce the proper sequence. It is also guaranteed to properly flush the output buffer.
Uh, no.

First, it's std::endl, as endl is a manipulator and a member of the std namespace, not a member of some class or namespace "cout" (cout is also an object).

Second, endl is not "preferred" to \n. Its meaning is equivalent to inserting a newline and then flushing the stream, and it should only be used when both actions are desired. You can insert newlines when that's all you want, or you can flush the stream if that's all you want (insert std::flush).

Happy hacking.
Advertisement
Oops... std::cout::endl was a brain fart. Thanks.

Good point on flushing the stream as well. Generally though it's my experience that newbies tend to expect a stream flush, which is why I didn't mention the semantics. In some cases this can be a performance issue when making heavy use of stream objects, which should probably be kept in mind during implementation.

However it's worth noting that endl is guaranteed to use the locally preferred \n vs. \r\n vs. \r line break formatter, which is not so much important with cout but can become important for file I/O.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Quote:I think he means:
#include <iostream>
using std::cout;
using std::endl;

Oh come now that's just crossing the line.
Quote:
cout << "Hello, Houston" << endl;

Yeah, I caught that after I hit submit and didn't feel like replacing the angle brackets on the edit screen.
Free Mac Mini (I know, I'm a tool)
Quote:Original post by igni ferroque
Quote:I think he means:
#include <iostream>
using std::cout;
using std::endl;

Oh come now that's just crossing the line.
Quote:
cout << "Hello, Houston" << endl;

Yeah, I caught that after I hit submit and didn't feel like replacing the angle brackets on the edit screen.



Okay, we are getting a bit off topic. The one thing I need to know is how to enter a code, then run it and get a resualt.
Command-B builds, Command-R runs and builds (if it wasn't already built). Also, you can add more files to the project (just so you know).
This is about Objective-C, not C++, but it is a good tutorial for learning to work with the MacOS developer tools:
Introduction to Developing Cocoa Objective-C Applications: A Tutorial
Free Mac Mini (I know, I'm a tool)
Quote:Original post by Roboguy
Command-B builds, Command-R runs and builds (if it wasn't already built). Also, you can add more files to the project (just so you know).


I am still confused. If I have a hello world code, in a text file to I save it as a .cpp then import it to xcode then build+run it?
Do I hit build, enter my code then hit run?
When you create a new C++ project, it will create a main.cpp file for you that you can edit. If you want to add additional files, you need to include them in the target before building the project.
Free Mac Mini (I know, I'm a tool)

This topic is closed to new replies.

Advertisement