Having Trouble: Basic C++ in OS X for school project

I am running XCode 3.0 for C++ development in a Mac environment.

I'm working on a school project; here is the basics of the requirements:
• Program must read a text file and output the text file as an HTML file with the proper tags
• Must be executed from the console in this fashion:

nameOfProgram "Name of the txt file.txt"

• Must use this code (provided by teacher):

#include <iostream>
#include <fstream>
using namespace std;
int main( int argc, char* argv[] ) {
ifstream infile( argv[1] );
char ch = 0;
while( infile.get( ch ) ) {
cout.put( ch );
}
}

I understand what the above code is supposed to do, but I can't execute a file that way in Terminal (to my knowledge). The only way I've been able to run my C++ executables is by first doing:

make FileName

And then:

open FileName

If I run it as "open FileName "Text File Name.txt" ; Then it will simply open both files separately.

So, how do I get this file to execute as required (without running Windows) and how do I get the file to read in from the txt file properly? It's not working!
To execute a program from the OS X terminal (Bash), assuming your current directory is where your application lives:

 
./programName parameter


If the parameter is a path to a file, you must provide either a relative or absolute path:

 
./programName "~/path/to/your/file.txt"
Last edited on
Lodger, that works perfectly. I can't thank you enough. I appreciate you taking some time out to give me a hand!

Cheers!
Happy to help :)

Don't forget that you can also run your application with the debugger (gdb) attached by using Apple + Y (Ensure that you're in debug mode - check the drop down menu on the top left)

Some other handy keyboard shortcuts whilst in the debugger:

Set/remove a breakpoint at the current line: Apple + \ (backslash)
Step over: Apple + Shift + O (not a zero)
Step into: Apple + Shift + I
Continue (until the next breakpoint is hit): Apple + Alt + P
Last edited on
Topic archived. No new replies allowed.