My task is to make a C++ program that will read, write, save, load and append a text file. I have two issues that I've been stuck on so far. The first being, how do you store the first argument entered by a user in a string using argv? Secondly, how do I create the program such that when the user enters in the command the program doesn't exit immediately after, so technically be in a while loop the whole time until prompted by a quit message? I've tried doing this already but my code also goes into a loop.
int main(int argc, char* argv[]) {
while (!inFile.eof()) {
inFile.open("userinput.txt");
getline(cin, line);
if (argc > 1) {
int result = strcmp(argv[1], "load");
if (result == 0) {
cout << "CORRECT" << endl;
}
else{
exit(1);
}
}
}
return 0;
}