When i want to create a fonction that opens file and write into it i get this error.I have tried to find out solutioun of the error on Google but i couldt get anything useful! here is the code whats the wrong? Thank you.
I guess im making someting wrong.You said that i couldnt pass them by copy yes i agree with you but i dont even know how to pass them by reference. Could you help me in that way? Thank you so much...
#include "stdafx.h"
#include <iostream>
#include <string>
#include <locale.h>
usingnamespace System;
usingnamespace std;
#include <fstream>
using std::fstream;
#include <cstdlib>
int Dosya_Ac(fstream Open_File)//opens and writes the file
{
// exit program if fstream could not open file
if (!Open_File)
{
cout<<"The file couldn't found !";
return (1);
}
string num,ders,not;
Open_File<<num << ders << not;
Open_File.close();// Close the file
}
int main()
{
fstream Yaz("C:\\Users\\Ertan\\Desktop\\C++\\Kodlar\\Datas.txt",ios::in);
string ad,soyad,no;
ad="XYZ";
soyad="ABC";
no="44556677";
Dosya_Ac(Yaz);
}
#include "stdafx.h"
#include <iostream>
#include <string>
#include <locale.h>
usingnamespace System;
usingnamespace std;
#include <fstream>
using std::fstream;
#include <cstdlib>
int Dosya_Ac(fstream & Open_File) //****Notice Open_file is now a reference parameter***
{
// exit program if fstream could not open file
if (!Open_File)
{
cout<<"The file couldn't found !";
return (1);
}
string num,ders,not;
Open_File<<num << ders << not;
Open_File.close();// Close the file
//***************
//You need a return statement here by the way<<===========
}
int main()
{
fstream Yaz("C:\\Users\\Ertan\\Desktop\\C++\\Kodlar\\Datas.txt",ios::in);
string ad,soyad,no;
ad="XYZ";
soyad="ABC";
no="44556677";
Dosya_Ac(Yaz);
}