展开全部
去C++的网站,基本各个库函数的例子都有,不过需要你会英语。请看参考资料链接。
// opening and closing a file
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream outfile;
outfile.open ("test.txt");
// >> i/o operations here <<
outfile.close();
return 0;
}
// print the content of a text file.
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile;
infile.open ("test.txt", ifstream::in);
int ch = infile.get();
while (infile.good()) {
cout << (char) ch;
ch = infile.get();
}
infile.close();
return 0;
}
// opening and closing a file
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream outfile;
outfile.open ("test.txt");
// >> i/o operations here <<
outfile.close();
return 0;
}
// print the content of a text file.
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile;
infile.open ("test.txt", ifstream::in);
int ch = infile.get();
while (infile.good()) {
cout << (char) ch;
ch = infile.get();
}
infile.close();
return 0;
}
参考资料: http://www.cplusplus.com/reference/iostream/ifstream/open/
展开全部
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile ( "input.txt" );
ofstream outfile ("output.txt");
if (infile.is_open() && outfile.is_open())
outfile << "both files are open.\n";
infile.close();
outfile.close();
return 0;
}
#include <fstream>
using namespace std;
int main () {
ifstream infile ( "input.txt" );
ofstream outfile ("output.txt");
if (infile.is_open() && outfile.is_open())
outfile << "both files are open.\n";
infile.close();
outfile.close();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
输出文件流 output file stream 用于向文件写数据(输出到文件) fstream 文件流,可以输入也可以输出,是上面两个的合体
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询