Does anyone have an idea on this error "error C2248"

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
		#include "stdafx.h"

		#include <iostream>

		#include <string>

		#include <locale.h> 
		using namespace System;

		using namespace std;



		#include <fstream>  

		using std::fstream;



		#include <cstdlib>

		


		int Dosya_Ac(fstream Open_File)//opens and writes the file
		{





		fstream Dosya("C:\\Users\\Ertan\\Desktop\\C++\\Kodlar\\New.txt",ios::out);

		Open_File=Dosya;



		 // exit program if fstream could not open file


		if (!Dosya)
		{


		cout<<"The file couldn't found !";

		return (1);

		}

		string num,ders,not;

		num="1234";

		ders="MATHS";

		not="A";

		Dosya<<num << ders << not;


		num="1234";

		ders="HISTORY";

		not="B";

		Dosya<<num << ders << not;



		num="1234";

		ders="ENGLISH";

		not="A";

		Dosya<<num << ders << not;


		Dosya.close();// Close the file



		}


		int main()
		{

		fstream Yaz("C:\\Users\\Ertan\\Desktop\\C++\\Kodlar\\Datas.txt",ios::out);



		Dosya_Ac(Yaz);



		}
Last edited on
You can't pass streams by copy - you have to pass them by reference
Hope this helps


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
      #include "stdafx.h"
		#include <iostream>
		#include <string>
		#include <locale.h> 
		using namespace System;
		using namespace std;

		#include <fstream>  
		using std::fstream;
		#include <cstdlib>

		


		int Dosya_Ac(fstream Open_File)//opens and writes the file
		{





		//fstream Dosya("C:\\Users\\Ertan\\Desktop\\C++\\Kodlar\\New.txt",ios::out);

		//Open_File=Dosya;



		 // exit program if fstream could not open file


		if (!Open_File)
		{


		cout<<"The file couldn't found !";

		return (1);

		}

		string num,ders,not;

		num="1234";

		ders="MATHS";

		not="A";

		Open_File<<num << ders << not;


		num="1234";

		ders="HISTORY";

		not="B";

		Open_File<<num << ders << not;



		num="1234";

		ders="ENGLISH";

		not="A";

		Open_File<<num << ders << not;


		Open_File.close();// Close the file



		}


		int main()
		{

		fstream Yaz("C:\\Users\\Ertan\\Desktop\\C++\\Kodlar\\Datas.txt",ios::out);



		Dosya_Ac(Yaz);



		}
and also i agree with guestgulkan .
oui, on doit utiliser pass by reference avec un stream, parce que les copy ctor et assignment operator sont privees, par design.
Thanx everyone who helped.i tried to pass them by reference but it still gives the same error:

Let's see what you have now.
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...
Post your code - that way we can see where we stand - so we can correct it - much easier that way - saves a lot of questions and guesswork
Ok. Here is the Code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "stdafx.h"
#include <iostream>
#include <string>
#include <locale.h> 
using namespace System;
using namespace 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);	



		}
You need to read up on functions and methods of passing parameters to functions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "stdafx.h"
#include <iostream>
#include <string>
#include <locale.h> 
using namespace System;
using namespace 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);	


}
Hey guestgulkan,im really greatful to you.Thank you so much. Have a nice day
Topic archived. No new replies allowed.