69,371
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
int main()
{
ofstream outfile( "out_file" );
ifstream infile( "in_file" );
if ( ! infile ) {
cerr << "error: unable to open input file!\n";
return -1;
}
if ( ! outfile ) {
cerr << "error: unable to open output file!\n";
return -2;
}
string word;
while ( infile >> word )
outfile << word << ' ';
return 0;
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void checkFile(string &in_file, string &out_file){
in_file="from";
out_file="to";
ofstream outfile(out_file);
ifstream infile(in_file);
if(!outfile){
cerr<<"error of outfile"<<endl;
}
if(!infile){
cerr<<"error of infile"<<endl;
}
}
int main()
{
string out_file;
string in_file;
checkFile(in_file,out_file);
cin.get();
return 0;
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void checkFile(string &in_file, string &out_file)
{
in_file="from.dat";
out_file="to.dat";
ofstream outfile(out_file.c_str());
ifstream infile(in_file.c_str());
if(!outfile){
cerr<<"error of outfile"<<endl;
}
if(!infile){
cerr<<"error of infile"<<endl;
}
}
int main()
{
string out_file;
string in_file;
checkFile(in_file,out_file);
cin.get();
return 0;
}
//相关改动自己详细看看
void checkFile(string &in_file, string &out_file){
in_file="from";
out_file="to";
fstream outfile;
fstream infile;//空对象
infile.open("from",ios::in);//直接打开
if(!infile)
{
cout<<in_file<<"不存在"<<endl;
}
else
{
cout<<in_file<<"存在"<<endl;
}
同理 out_file.....
}
WIN32_FIND_DATAW data;
HANDLE h = FindFirstFile(L"c:\\ss.txt",&data);
if (h == INVALID_HANDLE_VALUE)
{
printf("%s","不存在");
}