If there is argv[1] I want to put some data to new ofstream(argv[1]) i.e file with name argv[1]. But if there are no such argument I want to use cout instead.
I’ve tried
std::ostream& output = argc >= 1 ? std::fstream(argv[0]) : std::cout;
But it even doesn’t compile because of deleted constructor.
You can create an fstream instance and delay opening it until necessary.