Created
April 9, 2021 23:15
-
-
Save jherr/f625733bb7e133b9d3ea069b52cf563a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
// Generic print function that takes an output stream. | |
// Can be used to print to the screen by passing cout. | |
// Can be used to print to a file by passing a file stream. | |
void printSomething(ostream &out, string somethingToSay) { | |
out << "Something cool:" << somethingToSay << endl; | |
} | |
int main() { | |
// Print to the screen | |
printSomething(cout, "hey there"); | |
// Writes the same thing to a file | |
ofstream myfile; | |
myfile.open("example.txt"); | |
printSomething(myfile, "hey there"); | |
myfile.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment