输入输出:
1、包含头文件<fstream>
2、创建ifstream的对象,设置打印文件名(当前路径)
3、读取一个字符,输出一个字符
4、只要没有读取到文件末尾,就一直循环读取、输出
代码如下:
#include <iostream> #include<fstream> using namespace std; int main() { ifstream infile("14打印14的源代码.cpp",ios::binary); char ch; while(infile.peek()!=EOF) { infile.read(&ch,sizeof(ch)); cout<<ch; } cout<<endl; return 0; }
成功打印!