求几句c++语句实现判断文本文件是否有内容
2014-01-07
展开全部
#include <iostream>
#include <fstream>
using namespace std;#define FILENAME "Text.txt"int main()
{
fstream in_file,out_file;
out_file.open(FILENAME,ios_base::out);
char ch[] = "Hello World";
int i = 0;
while (ch[i] != '\0')
{
out_file<<ch[i++];
}
out_file.close();
in_file.open(FILENAME,ios_base::in);
i = 0;
memset(ch,0,strlen(ch));
while (!in_file.eof())
{
in_file>>ch[i];
cout<<ch[i++];
}
cout<<endl;
in_file.close();
return 0;
}//直接给你个参考吧
#include <fstream>
using namespace std;#define FILENAME "Text.txt"int main()
{
fstream in_file,out_file;
out_file.open(FILENAME,ios_base::out);
char ch[] = "Hello World";
int i = 0;
while (ch[i] != '\0')
{
out_file<<ch[i++];
}
out_file.close();
in_file.open(FILENAME,ios_base::in);
i = 0;
memset(ch,0,strlen(ch));
while (!in_file.eof())
{
in_file>>ch[i];
cout<<ch[i++];
}
cout<<endl;
in_file.close();
return 0;
}//直接给你个参考吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询