C++输入输出流
voidin(){cout<<"请输入路径:"<<endl;charinpath[50];cin>>inpath;ifstreaminf;inf.open(inpath,...
void in()
{
cout<<"请输入路径:"<<endl;
char inpath[50];
cin>>inpath;
ifstream inf;
inf.open(inpath,ios::in);
while (getline(inf, s))
{
cout<<s<<endl<<endl;
}
inf.close();
}
void out()
{
ofstream outf;
char outpath[50];
cout<<"请输入输出路径:"<<endl;
cin>>outpath;
outf.open(outpath,ios::out);
while (getline(inf, s))
{
outf<<s<<'\n';
}
outf.close();
}
第二个方法输出txt文件是空的。怎么改 展开
{
cout<<"请输入路径:"<<endl;
char inpath[50];
cin>>inpath;
ifstream inf;
inf.open(inpath,ios::in);
while (getline(inf, s))
{
cout<<s<<endl<<endl;
}
inf.close();
}
void out()
{
ofstream outf;
char outpath[50];
cout<<"请输入输出路径:"<<endl;
cin>>outpath;
outf.open(outpath,ios::out);
while (getline(inf, s))
{
outf<<s<<'\n';
}
outf.close();
}
第二个方法输出txt文件是空的。怎么改 展开
2个回答
展开全部
你的代码逻辑有一些问题,如下代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string inpath, outpath;
cout << "请输入路径:";
cin >> inpath;
cout << "请输入输出路径:";
cin >> outpath;
ifstream fin(inpath);
ofstream fout(outpath);
string line;
while (getline(fin, line)) {
fout << line << endl;
}
cout << "done." << endl;
fin.close();
fout.close();
system("pause");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询