#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int coutFile(char * filename,char * outfilename)
{
ifstream filein;
filein.open(filename,ios_base::in);
ofstream fileout;
fileout.open(outfilename,ios_base::out);
string strtemp;
int count=0;
while(getline(filein,strtemp))
{
count++;
cout<<strtemp<<endl;
fileout<<count<<" "<<strtemp<<endl;
}
filein.close();
fileout.close();
return count;
}
void main()
{
cout<<coutFile("c:\\data.txt","c:\\data1.txt")<<endl;
}
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
char data[100];
// open a file in write mode.
ofstream outfile;
outfile.open("afile.dat");
cout << "Writing to the file" << endl;
cout << "Enter your name: ";
cin.getline(data, 100);
// write inputted data into the file.
outfile << data << endl;
cout << "Enter your age: ";
cin >> data;
cin.ignore();
// again write inputted data into the file.
outfile << data << endl;
// close the opened file.
outfile.close();
// open a file in read mode.
ifstream infile;
infile.open("afile.dat");
cout << "Reading from the file" << endl;
infile >> data;
// write the data at the screen.
cout << data << endl;
// again read the data from the file and display it.
infile >> data;
cout << data << endl;
// close the opened file.
infile.close();
return 0;
}
$./a.out Writing to the file Enter your name: Zara Enter your age: 9 Reading from the file Zara 9
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有