C++ファイル操作のHelloWorld
632 ワード
以下はC++ファイル操作の入門で、簡単に参照して真似することができます.
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void main(void)
{
//
ofstream outfile("out.txt");
//
ifstream infile("in.txt");
//
if(!infile)
{
cerr<<"error: unable to open input file!
";
return;
}
//
if(!outfile)
{
cerr<<"error: unable to open output file!
";
return;
}
string word;
//
while(infile>>word)
{
outfile<<word<<" ";
cout<<word<<" ";
}
}