PDA

View Full Version : C++ Programming on Macs??




Sean7512
Jan 23, 2006, 11:56 PM
I am a freshman, and my major is Computing and Info Science. I'm now in my second class of C++ programming. We use all Windows XP computers, with the Microsoft Visual Studio Compiler. All of our programs simply open in a DOS window. Is there any way that I can use my Mac for the homework and stuff, and still be able to compile and test it???



excalibur313
Jan 24, 2006, 12:26 AM
Sure! Just install Xcode that comes on the os x dvd. It is a really nice program that I like better than the c++ program that microsoft makes. You can use Xcode to program in all sorts of languages. It's quite wonderful!

Soulstorm
Jan 24, 2006, 02:24 AM
Sure you can. All programs that are on OS X are typically made with xCode, which is in the DVD's that contain your system. It is free, and approx. 2gbytes.

In order to get yourself working, just install xCode, open it, and make a new project. In the dialog that appears that prompts you to select a king of application you want to make, select "C++ tool" and xCode do everything else for you.

You will soon discover that xCode is much better IDE than Microsoft's visual basic.

matix
Jan 24, 2006, 05:15 AM
I'm a comp sci major taking C++ Programming II, and I've used Visual Studio, Xcode, and pico/nano/kwrite/command line.

Overall, Xcode is definitley my favorite. Terminal is 2nd. Visual Studio just has that Microsoft feel that I've learned to hate. I can't stand it.

Give Xcode a shot. I find that I can code the assignments 2-3X faster (no Reality Distortion Field here ;) ) because of the UI. I've found that the error messages and warnings are detailed and help me program better. (since 2.0)

My favorite is the unused variable warning. Our prof is pushing good memory practices big time.

But seriously, I would take issue with your school using XP boxes only. IMO Computer Science students should be learning on the command line (just like at my school). If all they are teaching is how to click a 'build' button then you might have a hard time picking up a unix system and building a more complicated program... just my 2c

Voidness
Jan 24, 2006, 09:24 AM
I'm in Computer Engineering, and I used Xcode 2 to program in C++ for all my assignments in the Data Structures course. There's just one strange thing I went through when copying my code to a Windows PC to get a Windows Executable file. Although the code that I wrote in Xcode and tested on a Mac would compile in Microsoft Visual C++, the result program would just act like crazy! But when I compile the same code in a GCC compiler on Windows, it works just like how worked on the Mac. I still didn't figure out the problem, especially that I'm only using standard C++ libraries.

Another thing that I would like to point out is when copying your code to a Windows PC, be sure to change the line ending format in Xcode ( Format > Line Endings > Windows ). If you don't do so, your code will not be displayed correctly on Windows.

( Wasn't this same question asked multiple times on this forum? )

darkwing
Jan 24, 2006, 09:54 AM
I'm 4 months away from an MS degree in computer science and have used my Mac throughout my college career. I use XCode for c++ and java assignments, and I use it for cross-building to x86 linux targets for work as well. You will be just fine as long as you don't get into the Windows specific API. When you take an OOP/GUI class it will most likely be done in Java, anyway. While Apple's java VM is a slow pathetic piece of utter crap compared to the Windows version that Sun invested so much time and money in, you will find everything made with it looks prettier and makes for excellent screenshots to turn in. :)

Good luck!

Sean7512
Jan 24, 2006, 11:36 AM
I have started a new project, and inside the "main.cpp" file that was started for me, I just copy and pasted a program that I had previously written. Now, how can I build it and run it? I can't seem to figure it out.

Josh
Jan 24, 2006, 12:13 PM
I'm in the exact same scenario. We write, compile, and run our programs on XP boxes.

I don't have XP or any form of Windows at home, so I asked my prof. what he is looking for us to hand in as assignments - the .cpp file, a screenshot/print out, or an .exe file), because I won't be using Windows, but OS X to do my homework.

I'll be using xCode for this, but I'm not opposed to GNU's compiler either - terminal use is just fine for me (lol working in transparent windows makes typing seem more fun to me...) :)

Anyway...the other day my prof. was talking about OS's, and to quote him shortly..."...Windows...Unix/Linux...and whatever monster they've got on Apple's these days."

Apparently the CS courses here - or perhaps just my prof - are very Windows-oriented. Definitely not what I'd like to see. I'm more interested in the proper code and theory than OS-specific projects :mad:

Oh well...new school next fall, so I'm looking forward to that.

Voidness
Jan 24, 2006, 12:26 PM
I have started a new project, and inside the "main.cpp" file that was started for me, I just copy and pasted a program that I had previously written. Now, how can I build it and run it? I can't seem to figure it out.
If you're using Xcode 2, just click on the build icon located on the top toolbar in the project window. If you want to run it, just click on "Build and Go". You could also run your program from the terminal (after you build it in Xcode ofcourse).

Sean7512
Jan 24, 2006, 12:32 PM
Im using Xcode 1.1 I just used the "Installer" folder that was already on my harddrive. I prob have Xcode 2 at home on my Tiger DVD, correct? I keep getting erros with Xcode..I'll prob just wait until I get that DVD for the newer version.

Voidness
Jan 24, 2006, 12:41 PM
Yes, Xcode 2 is available on the Tiger DVD. I haven't worked withe Xcode 1, but it should be the same. What errors are you getting? How did you start a new project?

ChrisA
Jan 24, 2006, 01:08 PM
I am a freshman, and my major is Computing and Info Science. I'm now in my second class of C++ programming. We use all Windows XP computers, with the Microsoft Visual Studio Compiler. All of our programs simply open in a DOS window. Is there any way that I can use my Mac for the homework and stuff, and still be able to compile and test it???

I do this kind of stuf all day for a living. I started in the 70's. All of the IDEs I've seen have one problem in common: They lock you into one platform. So if you use MS Visual Studio You will have some effort if your code is to ever run on a non-MS platform. Of course "lock in" is the primary design goal of all MS software. Pretty much the same applies to Apple's xcode. Of course if you want to target ONLY one platform these IDE's work well.

I just use a terminal window, a text editor and somethimes a debugger. Or more accuratly many termial and text ediotr windows on several virtual screens. I'll use "make" as the build tool and lately I use GNU's "Autotools" (automake, autoconf and libtool) and I write with portibility in mind. It turns out that usful programs have a very long life, onger than any one platform.

With Java IDEs (like Eclipse) make sense but still a simple test editor works fine. I like "nedit" It does syntax hilighting, colum moves and macros and runs on _every_ platform under the sun. http://www.nedit.org/

Is this a four year university degree program? If so I'd expect them to offer only an introductory programming class and then go on to "data structures" or algorithm design or whatever. I think after the first class the proff didn't care what programing language we used for asignmants. I liked "PL/!" back then but.I remember using FORTRAN, LISP and various assembly languages too.

If they are only teaching c== on Windows it is really a disservice. They should be giving students a much wider experiance base including embeded micro processors (as found inside, say, a microwave oven or automobile) Perl scripting and bunch of other stuf.

therevolution
Jan 24, 2006, 11:28 PM
All of the IDEs I've seen have one problem in common: They lock you into one platform.

You mentioned Eclipse, yet you still think this? Eclipse is pretty much as far from single-platform lock-in as you can get. What's your reasoning?

AlmostThere
Jan 25, 2006, 05:28 AM
I do this kind of stuf all day for a living. I started in the 70's. All of the IDEs I've seen have one problem in common: They lock you into one platform. So if you use MS Visual Studio You will have some effort if your code is to ever run on a non-MS platform....(cut)


Even changing compiler can be a significant problem, let alone IDE. Not just between compilers, but different versions of the same compiler can break compatibility. These problems will always be rife and the benefits (from a practical point of view) are only really reaped if the intention is to be as portable as possible, which should really be decided from the onset, otherwise there is a significant and unnecessary overhead involved, not forgetting the benefits that platform specific tools can bring.

Serac
Jan 26, 2006, 03:31 PM
I actually have the exact inverse problem, but I was wondering if anybody could please help me.

With a semester of c++, I have learned enough that I want to code at my house. At school we use macs and xcode, and I'm very accustomed to the interface. However, with windows at home, I'm wondering if anybody knows of an interface similar to xcode except for windows? I installed something wierd and I didn't get it at all, the least to say that I couldn't program.

I'd greatly appreciate it if anbody could help me. :)

AlmostThere
Jan 26, 2006, 04:23 PM
Visual Studio is a free download (although slightly limited in terms of bundled libraries) and is the standard tool for Windows development.

http://msdn.microsoft.com/vstudio/express/visualc/

Otherwise you might want to try Dev-C++

http://www.bloodshed.net/devcpp.html

Or Eclipse with the CDT plug-in

http://www.eclipse.org/

Probably in that order.

Fender2112
Jan 26, 2006, 04:36 PM
I actually have the exact inverse problem, but I was wondering if anybody could please help me.

With a semester of c++, I have learned enough that I want to code at my house. At school we use macs and xcode, and I'm very accustomed to the interface. However, with windows at home, I'm wondering if anybody knows of an interface similar to xcode except for windows? I installed something wierd and I didn't get it at all, the least to say that I couldn't program.

I'd greatly appreciate it if anbody could help me. :)

You could get a Mac Mini. :D
I also took a semester of C++ at a local community college. There we used Visual C++. It's not like Xcode but I guess it's the best Microsoft has to offer. It's not hard going back and forth with beginner type exercises. I kept all my source files on a USB flash drive and added them as needed to whatever project I was working in.

bousozoku
Jan 26, 2006, 04:50 PM
Borland allows their Foundation versions of Delphi, C++Builder, and JBuilder to be downloaded for free. The products are quite nice but they're not like Xcode and, in my experience, nothing else is.

Serac
Jan 26, 2006, 06:57 PM
Thanks for the advice, I want to be able to run programs like this:

//JE
//1/26/06
//Power function

#include <iostream.h>

int main()
{
int a, b, c;
cout<<"Give me a number";
cin>>a;
b=a*a;
cout<<"The power of your number is... "<<b<<endl;
}




Those programs would let me run and test stuff like this correct?

bousozoku
Jan 26, 2006, 06:59 PM
Thanks for the advice, I want to be able to run programs like this:

//JE
//1/26/06
//Power function

#include <iostream.h>

int main()
{
int a, b, c;
cout<<"Give me a number";
cin>>a;
b=a*a;
cout<<"The power of your number is... "<<b<<endl;
}




Those programs would let me run and test stuff like this correct?

They probably would, but you should correct it anyway.

MacCoaster
Jan 26, 2006, 07:04 PM
Thanks for the advice, I want to be able to run programs like this:

//JE
//1/26/06
//Power function

#include <iostream.h>

int main()
{
int a, b, c;
cout<<"Give me a number";
cin>>a;
b=a*a;
cout<<"The power of your number is... "<<b<<endl;
}




Those programs would let me run and test stuff like this correct?
Uh, your C++ code isn't exactly the best and modern compilers will complain about lots of things.

First, with C++ there is no need for the ".h" in #include <iostream.h>, so you use #incluse <iostream> this applies to any class in the STL. You still need .h for others.

Second, the compiler will complain about the variable c being unused.

Third, related with #1... C++ has namespaces so all the STL stuff are under the std namespace, so you'd need to either declare "using namespace std;" or add the std:: scope before the cin and cout objects.

Finally, you can use the C math library by "#include <cmath>" and using the pow(double, double) function.

You don't need any of those programs, you can just install the Xcode tools and compile from the terminal.

Serac
Jan 26, 2006, 07:20 PM
right... it was just an example though. :P

I see now I didn't need b or c, I could have just done "a*=a;" or something. Thanks for the tips.

So I'm looking at the Dev program (I tried teh first program, but it was a hassle so i just quit! (It was so annoying, I had to install that program, but I needed the XP service pack 2, and then I couldn't get to that page because I needed internet explorer 5, then it wouldn't accept it when it was installing, all when everything was slow and then one thing made the whole computer restart and I had to go back and do the whole thing again, all to no useful end result... jeez, that's annoying.) and I think that may do it for me for my simple uses.... I want a beginner-friendly program, if it helps. :)

Also, is there any way to install mac os x on windows? I recall you could install windows/window stuff like microsoft word on a mac, is there a way to reverse it?

fuzzie
Jan 27, 2006, 11:27 AM
Also, is there any way to install mac os x on windows? I recall you could install windows/window stuff like microsoft word on a mac, is there a way to reverse it?

Word was a Mac program from the start, it's not 'windows stuff', sorry :) The Windows port is a rewrite.

You can emulate OS X on top of Windows with something like PearPC, but it's soooo slow. Maybe there will be progress on making the new Intel OS X versions work in vmware, like the development versions did, but that'd be running the whole OS.

sushi
Jan 28, 2006, 08:59 AM
Word was a Mac program from the start, it's not 'windows stuff', sorry :) The Windows port is a rewrite.
Just a minor correction.

Word was for DOS first, then Mac, then Windows.

FWIW, Excel was Mac first, then Windows.

T-Stex
Jan 28, 2006, 11:32 PM
I just use a terminal window, a text editor and somethimes a debugger. Or more accuratly many termial and text ediotr windows on several virtual screens. I'll use "make" as the build tool and lately I use GNU's "Autotools" (automake, autoconf and libtool) and I write with portibility in mind. It turns out that usful programs have a very long life, onger than any one platform.

That's more what I'm used to. I'm in my Junior year as a Computer Science & Engineering student, and we've used the emacs text editor and a terminal window almost exclusively, on Linux machines. I'm glad that we do this, and like it better than using Visual Studio or CodeWarrior, which we did in high school.

Timepass
Jan 29, 2006, 03:17 AM
Also rememeber when ever you code you assiments on a Mac make sure you test them on a native Windows XP computer (basicly you cannt use you mac for this) Some times it will compile just fine on a both a Mac and a PC but one compliled on a mac will just act wierd on a PC while the same code complied on a PC will work just fine. Some things are just wierd like that. A CS friend of mine who used a mac she ran into that problem a few times and she learned the hard way about that. The assiments are graded on a PC and they are tested on a PC by you TA. If they dont work your grade gets massively hurt.

bousozoku
Jan 29, 2006, 04:09 AM
Also rememeber when ever you code you assiments on a Mac make sure you test them on a native Windows XP computer (basicly you cannt use you mac for this) Some times it will compile just fine on a both a Mac and a PC but one compliled on a mac will just act wierd on a PC while the same code complied on a PC will work just fine. Some things are just wierd like that. A CS friend of mine who used a mac she ran into that problem a few times and she learned the hard way about that. The assiments are graded on a PC and they are tested on a PC by you TA. If they dont work your grade gets massively hurt.

The assignments, if written properly, should work on either without a problem. The only time you might wind up with a problem is when you create data on a Mac and try to read it on an x86 machine since the x86 machine has the MSB and LSB backwards from the rest of the computerdom.

Just a minor correction.

Word was for DOS first, then Mac, then Windows.

FWIW, Excel was Mac first, then Windows.

We could go into MacWrite and Multiplan to further the history lesson. :p

Mac Player
Jan 29, 2006, 07:02 AM
If u want to test the aplications u code on the Mac just get Virtual PC and install visual c++ express, microsoft is offering it free until November