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

airkarol

macrumors 6502
Original poster
Nov 12, 2005
280
0
Hi,

I am taking a C++ course at my university. A lot of assignments require me to make a single .cpp file with a given name. I haven't been able to get them to run unless part of a project in XCode, with the name main.cpp.

How can I run / compile single .cpp files using XCode Tools, or is there a better compiler to use? The school recommends Bloodshed Dev C++, but that is not available for OS X.

Also, I have to print out screenshots of what would normally be seen in the Command Prompt window on Windows. The only thing I've seen so far for showing I/O is the debugging console; however there is also a lot of useless information on there, such as the toolbar at the top, and information displayed while the program is running. Could it run in Terminal without all of that?

Thanks in advance for the help,

David
 
It's been many years since I've done this, but I think that there is (or at least used to be) a project type called "C++ Tool". This makes a "clean" console app.
 
If it's just a single cpp file, don't even bother with XCode. Open Terminal, write your code, compile it with g++ and run from the command line. XCode uses gcc/g++ for compilation so using it doesn't gain you anything but syntax highlighting, that you can get using something like TextWrangler (others will have favourite editors they can tell you about)
 
Hi,

I am taking a C++ course at my university. A lot of assignments require me to make a single .cpp file with a given name. I haven't been able to get them to run unless part of a project in XCode, with the name main.cpp.

How can I run / compile single .cpp files using XCode Tools, or is there a better compiler to use? The school recommends Bloodshed Dev C++, but that is not available for OS X.

Also, I have to print out screenshots of what would normally be seen in the Command Prompt window on Windows. The only thing I've seen so far for showing I/O is the debugging console; however there is also a lot of useless information on there, such as the toolbar at the top, and information displayed while the program is running. Could it run in Terminal without all of that?

Thanks in advance for the help,

David

The name of the "main.cpp" file can be changed within an Xcode project by right-click and selecting "Rename" in the resulting popup-menu.

If using Mac OS 10.6.x a user selectable area screen capture can be done using Command-Shift-4, selecting the area you wish to capture and pressing the mouse button. The captured image will be written to your Desktop.
 
I use Xcode as a text editor, but I compile in Terminal. Do whatever would be most efficient for you. It certainly would make sense to consolidate everything into the command line.
 
The name of the "main.cpp" file can be changed within an Xcode project by right-click and selecting "Rename" in the resulting popup-menu.

If using Mac OS 10.6.x a user selectable area screen capture can be done using Command-Shift-4, selecting the area you wish to capture and pressing the mouse button. The captured image will be written to your Desktop.

For some reason the entire window has to be in the screenshot, ie. the top bar of the program. When renaming the file in Xcode, I get an error having to do with the main.cpp file not being there, even though i defined a main function within the file.

If it's just a single cpp file, don't even bother with XCode. Open Terminal, write your code, compile it with g++ and run from the command line. XCode uses gcc/g++ for compilation so using it doesn't gain you anything but syntax highlighting, that you can get using something like TextWrangler (others will have favourite editors they can tell you about)

I've successfully compiled with g++; however, I haven't been able to figure out how to run the file.
 
I've successfully compiled with g++; however, I haven't been able to figure out how to run the file.

If you used the -o argument to give it a name, run it like
Code:
./name
where name is what you passed to -o. If you didn't, run it like:
Code:
./a.out
 
I've found that the easiest way to program in class is to use the C++ console app and run it within XCode's console. The console is located under the Run menu.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.