C++ program with args (eg myprogram.exe -n)
Nov 10, 2010 at 1:00am Nov 10, 2010 at 1:00am UTC
I have tried to learn about this but still don't understand it.
Lets say I want a program that writes a message to a file:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string message[3] = {"a" , "b" , "c" };
ofstream f;
f.open("C:\file.txt" );
f >> message[0];
f.close()
}
How would I rewrite the obove program so I could use a script that says:
myprogram.exe 0 //creates file with "a"
myprogram.exe 2 //creates file with "c"
myprogram.exe 1 //creates file with "b"
Thanks.
-Mike
Nov 10, 2010 at 2:28am Nov 10, 2010 at 2:28am UTC
Nov 10, 2010 at 3:25am Nov 10, 2010 at 3:25am UTC
Thankyou just what I needed.
Topic archived. No new replies allowed.