PDA

View Full Version : کلاس های فایل ؟؟؟



m.khani_121
سه شنبه 18 بهمن 1390, 11:39 صبح
من این header تو visual studio میزنم ولی بازم تابع های fstream نمیشناسه !!
#include "fstream"
#include "iostream"
#include "stdlib.h"
#include "stdafx.h"

یعنی بازم کلاس داره که من نزدم یا ؟؟

error اینه :
Error 4 error C2065: 'ofstream' : undeclared identifier

Altech
سه شنبه 18 بهمن 1390, 11:46 صبح
چرا داخل گیومه قرار میدین fstream و اینارو ؟
با <> امتحان کردین ؟

m.khani_121
سه شنبه 18 بهمن 1390, 12:09 عصر
چرا داخل گیومه قرار میدین fstream و اینارو ؟
با <> امتحان کردین ؟

دارم با visual studio مینویسم !! فرقی میکنه ؟؟

Altech
سه شنبه 18 بهمن 1390, 12:13 عصر
using namespace std; رو هم بعد از include ها نوشتین ؟

m.khani_121
سه شنبه 18 بهمن 1390, 12:22 عصر
using namespace std; رو هم بعد از include ها نوشتین ؟


// file.cpp : Defines the entry point for the console application.
//


#include "fstream"
#include "iostream"
#include "stdlib.h"
#include "stdafx.h"
#include "conio.h"

using namespace std;


using std::cin;
using std::cout;
using std::endl;


int _tmain(int argc, _TCHAR* argv[])
{
char ch;
ofstream fp("test.dat");
if(!fp)
{
cout<<" cannot open file "<<endl;
exit(0);
}
cout<<" enter characters ( $ is end ) "<<endl;
do
{
cinget(ch);
fp.put(ch);
}while(ch!='$');
fp.close();
cout<<" output from file "<<endl;
ifstream fp1("test.dat");
fp1.get(ch);
while(!fp1.eof())
{
cout.put(ch);
fp1.get(ch);
}
fp1.close();
cout<<endl<<" output completed ";
getch();
return 0;
}



اینم کدش !!

m.khani_121
سه شنبه 18 بهمن 1390, 12:26 عصر
این کد برنامه ...

Altech
سه شنبه 18 بهمن 1390, 12:48 عصر
من این کدو نوشتم اجرا شد :



#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <conio.h>

using namespace std;




int main()
{
char ch;
ofstream fp("test.dat");
if(!fp)
{
cout<<" cannot open file "<<endl;
exit(0);
}
cout<<" enter characters ( $ is end ) "<<endl;
do
{
cin.get(ch);
fp.put(ch);
}while(ch!='$');
fp.close();
cout<<" output from file "<<endl;
ifstream fp1("test.dat");
fp1.get(ch);
while(!fp1.eof())
{
cout.put(ch);
fp1.get(ch);
}
fp1.close();
cout<<endl<<" output completed ";
getch();
return 0;
}

m.khani_121
چهارشنبه 19 بهمن 1390, 01:10 صبح
تو visual زدم اجرا نشد !!!

Altech
چهارشنبه 19 بهمن 1390, 12:50 عصر
تو visual زدم اجرا نشد !!!

وقتی پروژه کنسول ایجاد می کنین بعدش باید تو پنجره ای که باز میشه تیک Empty Project رو بزنین .

m.khani_121
چهارشنبه 19 بهمن 1390, 13:40 عصر
وقتی تیکو میزنم دیگه هیچی نمیاره که !!!