C++ Create file if argc==2? -
i cannot figure out wrong here... want code create file when type 1 argument in terminal. works fine if argc set 1, not above that. appreciated ! cheers & nice sunday
#include <fstream> #include <string> #include <iostream> using namespace std; int main(int argc, char* argv[]) { if (argc==(2)) { ofstream file("myfile.txt"); // creates myfile.txt } else { cout << "type 1 argument !" << endl; } return 0; }
if using visual studio answer : go project/properties, select "debugging" tab, , enter arguments in "command arguments" field.
Comments
Post a Comment