I'm new to c++, I'm trying to print a string to both console and a file at the same time.
I know this works:
but is there a better way to do it without repeat the code? Because the actual stuff I'm going to print is more complicated than the example above.Code://This is just an example cout<<"I want to print "<<3+4<<" in to a file."<<endl; ofstream out("file.txt"); out<<"I want to print "<<3+4<<" in to a file."<<endl;