c++infile问题
intmain(){fstreaminfile;fstreamoutfile;infile.open("C:\123.test.txt",ios::in);if(!inf...
int main()
{
fstream infile;
fstream outfile;
infile.open("C:\123.test.txt", ios::in);
if (!infile)
{
cout << "Error occurred while opening test.txt" << endl;
return 0;
}
outfile.open("C:\\123\test2.txt", ios::out);
if (!outfile)
{
cout << "Error occurred while opening test.txt2" << endl;
return 0;
}
char ch;
while (infile.get(ch));
outfile.put(ch);
infile.close();
outfile.close();
return 0;
为啥一直Error occurred while opening test.txt,我怎么写不进去? 展开
{
fstream infile;
fstream outfile;
infile.open("C:\123.test.txt", ios::in);
if (!infile)
{
cout << "Error occurred while opening test.txt" << endl;
return 0;
}
outfile.open("C:\\123\test2.txt", ios::out);
if (!outfile)
{
cout << "Error occurred while opening test.txt2" << endl;
return 0;
}
char ch;
while (infile.get(ch));
outfile.put(ch);
infile.close();
outfile.close();
return 0;
为啥一直Error occurred while opening test.txt,我怎么写不进去? 展开
1个回答
展开全部
你要先确定该文件是否存在,"C:\123.test.txt"
看你写的文件推算你可能写错路径了
infile.open("C:\123.test.txt", ios::in);
改成
infile.open("C:\\123\\test.txt", ios::in);
outfile.open("C:\\123\test2.txt", ios::out);
改成
outfile.open("C:\\123\\test2.txt", ios::out);
注意一个反斜杠的地方要写成2个反斜杠
看你写的文件推算你可能写错路径了
infile.open("C:\123.test.txt", ios::in);
改成
infile.open("C:\\123\\test.txt", ios::in);
outfile.open("C:\\123\test2.txt", ios::out);
改成
outfile.open("C:\\123\\test2.txt", ios::out);
注意一个反斜杠的地方要写成2个反斜杠
更多追问追答
追问
我在c盘建立了123文件夹,然后里面有两个文本文档命名为test.txt和test2.txt,哪不对吗?
追答
那就是你代码写错了,按我那样修改那两句就对了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询