Generation

generate functionSat, 12 Nov 2022

Get input from command line and store to a file

int main(int argc, char **argv) { if(argc < 2) { cout << "Please pass the file name to write to" << endl; return -1; } string filename = argv[1]; ofstream out(filename); if(!out) { cerr << "Cannot open file " << filename << endl; return -1; } string line; while(getline(cin, line)) { out << line << endl; } out.close(); return 0; }

Want to kickstart your project?Use the new AI Studio to create your code