请高手帮忙分析下一下程序哪有问题。

#include<iostream>#include<string>#include<fstream>intmain(){ofstreamoutfile("out_fil... #include<iostream>
#include<string>
#include<fstream>
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;
}

编译错误提示:error C2065: 'ofstream' : undeclared identifier
D:\3\12.cpp(6) : error C2146: syntax error : missing ';' before identifier 'outfile'
D:\3\12.cpp(6) : error C2065: 'outfile' : undeclared identifier
D:\3\12.cpp(7) : error C2065: 'ifstream' : undeclared identifier
D:\3\12.cpp(7) : error C2146: syntax error : missing ';' before identifier 'infile'
D:\3\12.cpp(7) : error C2065: 'infile' : undeclared identifier
D:\3\12.cpp(8) : error C2065: 'cerr' : undeclared identifier
D:\3\12.cpp(8) : error C2297: '<<' : illegal, right operand has type 'char [34]'
D:\3\12.cpp(10) : error C2143: syntax error : missing ';' before '}'
D:\3\12.cpp(11) : error C2297: '<<' : illegal, right operand has type 'char [35]'
D:\3\12.cpp(14) : error C2065: 'string' : undeclared identifier
D:\3\12.cpp(14) : error C2146: syntax error : missing ';' before identifier 'word'
D:\3\12.cpp(14) : error C2065: 'word' : undeclared identifier
D:\3\12.cpp(16) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
看不懂饿
我是用VC++6.0编译的
展开
 我来答
junjie1304
2009-07-19 · TA获得超过360个赞
知道答主
回答量:248
采纳率:0%
帮助的人:0
展开全部
// Test.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

void inFile();

ifstream infile;
ofstream outfile;
char name[30],a,str[1024];

float b;

int _tmain(int argc, _TCHAR* argv[])
{
cout<<"请你选择要进行的操作:"<<endl;
cout<<"1读取文件!"<<" "<<"2创建和写入文件!"<<" "<<"3删除文件!"<<endl;
cin>>b;
if (b==1.0f)
{
inFile();
if (!infile)
{
cout<<"未找到名称为 "<<name<<" 的文件!!"<<endl;
inFile();
}else
{
cout<<"成功找到文件<<"<<name<<">>内容如下:"<<endl;
}

while (infile.get(a))
{
cout<<a;
}
cout<<endl;
infile.close();
}else if (b==2.0f)
{
cout<<"请输入要写入文件的文件名:"<<endl;
cin>>name;
outfile.open(name);
if (!outfile)
{
cout<<"没找到<<"<<name<<">>"<<endl;
exit(1);
}
cout<<"成功创建<<"<<name<<">>"<<"请输入要写入的内容:"<<endl;
cin>>str;
outfile<<str;
outfile.close();
}
else if (b==3.0f)
{
cout<<"请输入要删除的文件名:"<<endl;
cin>>name;
if (!remove(name))
{
cout<<"文件"<<name<<"以删除"<<endl;
}
else
{
cout<<"文件"<<name<<"删除失败!"<<endl;
}

}else
{
cout<<"程序即将退出!下次开启时请按下1,2,3进行选择!!!"<<endl;
}
return 0;
}
void inFile()
{
cout<<"请输入要读取的文件名:"<<endl;
cin>>name;
infile.open(name);
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式