有几种,
C++首先继承了C的用法:
freopen("filename.txt","r",stdin);
freopen("filename.txt","w",stdout);
详见http://baike.baidu.com/view/656692.htm?fr=aladdin
C++还有自己的用法:
#include
ifstream file1("filename1.txt");
ofstream file1("filename1.txt");
或
fstream file1;
file1.open("filename1.txt");
详见http://soft.chinabyte.com/database/460/11433960.shtml
使用 fstream