C++ Programming on Macs??

Discussion in 'Mac Programming' started by Sean7512, Jan 23, 2006.

  1. Sean7512 macrumors 6502a

    Jun 8, 2005
    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???
  2. excalibur313 macrumors 6502a


    Jun 7, 2003
    Cambridge, MA
    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!
  3. Soulstorm macrumors 68000


    Feb 1, 2005
    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.
  4. matix macrumors member

    Apr 24, 2005
    Vancouver, BC
    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
  5. Voidness macrumors 6502a


    Aug 2, 2005
    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? )
  6. darkwing macrumors 65816

    Jan 6, 2004
    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!
  7. Sean7512 thread starter macrumors 6502a

    Jun 8, 2005
    Compile (Build)

    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.
  8. Josh macrumors 68000


    Mar 4, 2004
    State College, PA
    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.
  9. Voidness macrumors 6502a


    Aug 2, 2005
    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).
  10. Sean7512 thread starter macrumors 6502a

    Jun 8, 2005
    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.
  11. Voidness macrumors 6502a


    Aug 2, 2005
    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?
  12. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    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.
  13. therevolution macrumors 6502

    May 12, 2003
    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?
  14. AlmostThere macrumors 6502a

    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.
  15. Serac macrumors newbie

    Jan 26, 2006
    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. :)
  16. AlmostThere macrumors 6502a

  17. Fender2112 macrumors 65816


    Aug 11, 2002
    Charlotte, NC
    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.
  18. bousozoku Moderator emeritus

    Jun 25, 2002
    Gone but not forgotten.
    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.
  19. Serac macrumors newbie

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

    //Power function

    #include <iostream.h>

    int main()
    int a, b, c;
    cout<<"Give me a number";
    cout<<"The power of your number is... "<<b<<endl;

    Those programs would let me run and test stuff like this correct?
  20. bousozoku Moderator emeritus

    Jun 25, 2002
    Gone but not forgotten.
    They probably would, but you should correct it anyway.
  21. MacCoaster macrumors 6502a


    Jul 15, 2002
    Washington, DC / Rochester, NY / Lexington, NC
    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.
  22. Serac macrumors newbie

    Jan 26, 2006
    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?
  23. fuzzie macrumors newbie

    Jun 20, 2004
    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.
  24. sushi Moderator emeritus


    Jul 19, 2002
    Just a minor correction.

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

    FWIW, Excel was Mac first, then Windows.
  25. T-Stex macrumors 6502

    Jan 15, 2006
    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.

Share This Page