I have written some C++ code in Visual Studio (VS), which uses some command line parameters; (argc, argv)
.
However, when I run it from inside VS, it shows this error message and stops working.
The project is a Win32 Console application.
Also, I don't know how to provide arguments to the program when running from within VS.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 3)
cerr << "Please input valid file name";
int year;
ifstream in(argv[1]);
ofstream out;
out.open(argv[2], ofstream::app);
if (out) {
//cout << "Input year:" << endl;
while (in >> year)
if ((year % 4) == 0 && (year % 100) != 0 || (year % 400) == 0)
out << year << " is a leap year" << endl;
else out << year << " is not a leap year" << endl;
}
else
cerr << "can not open! Try again";
return 0;
}