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; }