I'm trying to make a program in which you run the program in command prompt, and you type a message that is saved in a file. That file's dir is typed in the arguments when you first run it from command prompt. For some reason I always get and error and I'm not sure why I get an error. Can someone explain to me why I'm getting an error and what I need to fix?
argv is a char**, so string dir(argv); makes no sense. It should be string dir(*argv); or string dir(argv[0]);
The first "string" in argv is the name of the program.
The first parameter is in argv[1].
Before reading it you should make sure an argument was provided:
1 2 3 4 5 6 7 8
string dir;
if( 2 == argc )
dir = argv[1];
else
{
cout << "Wrong number of arguments" << endl;
return 1;
}
Also, file >> wrote; reads from the file.
To write to it, it's file << wrote;