PDA

View Full Version : سوال: چاپ کردن نتیجه در یک فایل txt



DR.HTML
شنبه 22 بهمن 1390, 13:51 عصر
سلام دوستان بنده برنامه ای دارم چطوری میتونم نتیجه قسمتهاییو که توی سورس نشون دادم توی یک فایل txt هم چاپ کنه غیر از خود برنامه این سورس برنامه
#include<iostream>
#include<conio>
void main(){
int r,m=0,r1,shg,shb,rf,ms,i=0;
char tn[10],tb[10],sh[10];
cout<<"tedad radif:";
cin>>r;
for(i=0;i<r;i++)
{cout<<"shomare radif:";
cin>>r1;
cout<<"shomare name:";
cin>>sh;
cout<<"tarikh name:";
cin>>tn;
cout<<"shomare ghabz:";
cin>>shg;
cout<<"shomare bestankari:";
cin>>shb;
cout<<"tarikh bestankari:";
cin>>tb;
cout<<"radif fehrest ersali:";
cin>>rf;
cout<<"mablagh seporde:";
cin>>ms;
m+=ms;
cout.width(5);
cout<<r1; //in chap beshe
cout.width(10);
cout<<sh; //in chap beshe
cout.width(10);
cout<<tn; //in chap beshe
cout.width(10);
cout<<shg; //in chap beshe
cout.width(10);
cout<<shb; //in chap beshe
cout.width(10);
cout<<tb; //in chap beshe
cout.width(5);
cout<<rf;//in chap beshe
cout.width(16);
cout<<ms; //in chap beshe
cout<<"\n";
}
cout<<"EO"<<" "<<2195083653002; //in chap beshe
cout.width(5);
cout<<r; //in chap beshe
cout.width(16);
cout<<m<<endl; //in chap beshe
getch();
}

البته به همین شکلی که توی برنامه هم نشون داده میشه

pe32_64
شنبه 22 بهمن 1390, 15:28 عصر
شما باید کار با فایل رو یاد بگیری
http://www.cplusplus.com/doc/tutorial/files/
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}