++编程,请问如何向文件中插入数据?不覆盖原来内容
最好是能写个小程序。C++中#include<iostream>#include<fstream>#include<string>usingnamespacestd;vo...
最好是能写个小程序。
C++中
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
string filename;
cout<<"Enter the filename :\n";
cin>>filename;
filename=filename+".txt";
ofstream fout(filename.c_str());
fout<<"write something to this file!^^";
fout.close();
ifstream fin(filename.c_str());
string s;
while(getline(fin,s))
{
cout<<s<<endl;
}
fin.close();
cin.get();
} 展开
C++中
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
string filename;
cout<<"Enter the filename :\n";
cin>>filename;
filename=filename+".txt";
ofstream fout(filename.c_str());
fout<<"write something to this file!^^";
fout.close();
ifstream fin(filename.c_str());
string s;
while(getline(fin,s))
{
cout<<s<<endl;
}
fin.close();
cin.get();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询