C++ 中关于文件的读入和输出(转载)- - C++ 中关于文件的读入和输出
Example : 从 in
txt 文件中读入数据,并输出到 out
txt 中,输出的文件中每行之间有一空行相隔 #include #include #include using namespace std; int main (int){ string s; ifstream inf; inf
open("in
txt"); //打开输出文件 ofstream outf; outf
open("out
txt"); //从 in
txt 文件中读入数据,并输出到 out
txt 中 /*其中 getline(参 1,参 2); 作用是从 inf 指向的文件中 每次读入一行,把数据存到字符串 s 中,从第一行开始 每读完一行后,系统自动地把指针指向下一行,不用人为 干预*/ while( getline(inf,s ) ){ outf