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

MihaiBucataru

macrumors newbie
Original poster
Mar 5, 2011
4
0
I'm new in programming and I've switched from Windows to Mac but I have a problem in programming, I have to do my homework for school in c++ using input and output files :(. Can I do it with Xcode?
 
I'm new in programming and I've switched from Windows to Mac but I have a problem in programming, I have to do my homework for school in c++ using input and output files :(. Can I do it with Xcode?

Of course you can. Just choose the c++ template in Xcode.

Edit: Pick application in the left pane of your "New Project" window, then pick "Comman Line Tool" and lastly, change the type to C++ stdc++.
 
Of course you can. Just choose the c++ template in Xcode.

Edit: Pick application in the left pane of your "New Project" window, then pick "Comman Line Tool" and lastly, change the type to C++ stdc++.

I already did that but I don't know where I can put my input and output files I tried New File/C++ Header File but I don't know why it doesn't work.
 
I already did that but I don't know where I can put my input and output files I tried New File/C++ Header File but I don't know why it doesn't work.

You will need to provide a file path to the files when you opening them for reading. But, honestly with only one source file it's probably less confusing to just use the command line and the g++ compiler.
 
You will need to provide a file path to the files when you opening them for reading. But, honestly with only one source file it's probably less confusing to just use the command line and the g++ compiler.

Heh, I would like to be able to do that but the only way to work for school and verify my programs is to send them at school's online evaluator but for that I have to use the fstream library, on MinGW(Windows) I was just
#include <fstream.h>
ifstream fin("NAME.in");
ofstream fout("NAME.out");
And then add 2 header files NAME.in and NAME.out, I tried the same on Xcode but it's not working :(.
 
Heh, I would like to be able to do that but the only way to work for school and verify my programs is to send them at school's online evaluator but for that I have to use the fstream library, on MinGW(Windows) I was just
#include <fstream.h>
ifstream fin("NAME.in");
ofstream fout("NAME.out");
And then add 2 header files NAME.in and NAME.out, I tried the same on Xcode but it's not working :(.

I does work. The problem you get is that the file is placed where the executable is. Now, you choose to work with an IDE, which means that you executable is inside a folder structure called a project. It's there to keep track of all resources of your enormous project.

Look inside your project folder, you will find an executable file in there (with a black exec icon) put your files there.

But as I said, you can use the terminal instead and compile manually.
 
You mean at Products? I also tried there but still my output file is empty:(.

No. When you create an Xcode project you get a folder somewhere, (desktop, documents or where ever you choose to save it) named after you project.

Or, you can simply drag out the main.cpp file to your desktop and throw away the project. Then compile manually. Edit: In this case you can still use Xcode as an editor, no problem.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.