خروجی در نوت پد؟

young-prog

New Member
با سلام
می خواستم ببینم چطوری میشه خروجی یه برنامه رو توی یه فایل notpad ذخیره بشه
منظورم اینه که کد این کارو برام بنویسین توی ++c
 

MnavidM

Active Member
young-prog گفت:
با سلام
می خواستم ببینم چطوری میشه خروجی یه برنامه رو توی یه فایل notpad ذخیره بشه
منظورم اینه که کد این کارو برام بنویسین توی ++c
سلام.

فکر کنم منظور شما این هست که خروجی , مثلا در یک فایل txt باشد .

برای این کار باید با قسمت کار با فایل (متنی) کار کنید .

موفق باشی.
 

saalek110

Well-Known Member
First Things First......................
______________
First thing to do is to include the header file fstream.h
like this...#include<fstream.h>
2)next thing is to declare the stream object example
fstream skuddy;
3)third thing is to use open method to initialize it
skuddy.open("filename",filemode);
where filename stands for a valid file location & filemode for
the below
ios::in -open for input
ios::eek:ut-open for output
ios::binary-open in binary mode
ios::app-open for appending
ios::nocreate-do not create the file if it does not exist
ios::noreplace-ditto,do not replace(if the file exists)
ios::trunc-destroys data in existing file

phew! thats it. u can input & output as shown in the following
program

#include<fstream.h>
#include<conio.h>
void main()
{
int n;
fstream skuddy;
skuddy.open("inter.txt",ios::eek:ut);
cin>>n;
skuddy<<n;
skuddy.close();

}
اين برنامه را من چك كردم. چند خط كد بالا را. كارش اينه كه يك عدد از كاربر مي خواهد و بعد يك فايل تكست ايجاد مي كنه به نام اينتر و آن عدد را در آن يادداشت مي كنه.

now read inter.txt with a text editor u will find an integer value
similaly u can output as..


#include<fstream.h>
#include<conio.h>
void main()
{
int n;
char ch;
fstream skuddy;
skuddy.open("inter.txt",ios::in);
skuddy>>n;
cout<<n;
getch();
skuddy.close();
}​
از آدرس:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=9498&lngWId=3
كاملش را مي توانيد بگيريد.
 
آخرین ویرایش:

جدیدترین ارسال ها

بالا