C style
FILE * fileptr
filename="C:\\file.txt"
fopenfclosefprintf
C++ style
//指向std::ostream的指针
#include <iostream>
#include <fstream>int main() {std::ostream* output = &std::cout; // 默认指向控制台// 输出到控制台*output << "Hello, Console!" << std::endl;// 切换到文件std::ofstream file("output.txt");output = &file;*output << "Hello, File!" << std::endl;// 恢复控制台输出output = &std::cout;*output << "Back to Console!" << std::endl;file.close();return 0;
}