Need help

May 28, 2011 at 10:58pm
i use embarcadero rad studio xe 2010 and for a button i have this code:


void __fastcall TfrmCont_nou_elev::btnSalvare_modificari_elevClick(TObject *Sender)

{

//++++++++++++++++++++++++++++++++++++++++++++++

ofstream Admini("Admini.txt", ios::app);


//CITESTE SI SALVEAZA MODIFICARILE


// NUME
char nume[500];
nume = edtNume_elev->Text;
Admini>>nume;










//PRENUME

//CLASA

//PAROLA

//NR. MATRICOL


Admini.close();
}



when i prees compile i'll have this errors:
1)
Cannot convert UnicodeString to Char
2)operator << not implemented in type ofstram for argument char






May 29, 2011 at 6:22am
Second post that I see with class names similar to Turbo Pascal's Turbo Vision, and now I think why: Embarcadero bought Borland's products some time ago.

As for your problem: I guess edtNume_elev->Text returns a Unicode string, and you are trying to store that in a char array; it at least should be an array of wchar_t. I also don't think you can do what you are doing: You cannot change the "value" of nume by assigning Text to it. You most likely need to copy the string using strncpy(), or most appropriately, wcsncpy() for wide char strings.

As for the use of Admini, I am not sure what you want to accomplish. If it is an output file stream, shouldn't you use operator<< instead?

And please use [code]//Paste code here. [/code] tags to show code.
Last edited on May 29, 2011 at 6:23am
Jun 2, 2011 at 2:57pm
how to use wchar?
Jun 2, 2011 at 4:08pm
1
2
//NUME
wchar_t nume[500]; //This is 500 wide characters. 
Jun 2, 2011 at 4:41pm
not working
Jun 2, 2011 at 4:41pm
same errors
Jun 2, 2011 at 5:00pm
See if this works...

ofstream Admini(_T("Admini.txt"), ios::app);
Jun 2, 2011 at 5:20pm
Of course same errors. That is not the only modification that you need to use. I told you you cannot just set the Text property to nume. I told you that you needed to copy it using wcsncpy(). Have you tried copying it?

As for Admini, have you tried using operator<< instead?? Show your updated code to see how much you have advanced so far.

By the way, if Text returns a pointer, and if you are not changing the text, you could just receive the pointer like this:

wchar_t *nume =edtNume_elev->Text;
Jun 4, 2011 at 8:21am
Hi, show me how to set wcsncpy();
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
//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#include <fstream>
#include <iostream.h>
#include <conio.h>
#include <string.h>
#pragma hdrstop
using namespace std;


#include "Cont_nou_elev.h"
#include "Autentificare.h"
#include "Cont_nou_profesor.h"

#include "Directiune.h"
#include "Admin_conturi.h"
#include "Cont_nou.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"






TfrmCont_nou_elev *frmCont_nou_elev;
//---------------------------------------------------------------------------
__fastcall TfrmCont_nou_elev::TfrmCont_nou_elev(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmCont_nou_elev::btnInapoi_cont_nou_elevClick(TObject *Sender)
{
frmCont_nou_elev->Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmCont_nou_elev::btnSalvare_modificari_elevClick(TObject *Sender)

{

				//++++++++++++++++++++++++++++++++++++++++++++++

 ofstream Admini(_T("Admini.dll"), ios::app);


 //CITESTE SI SALVEAZA MODIFICARILE


 // NUME
                                wchar_t *nume =edtNume_elev->Text;

                                Admini>>nume;


               //  wcsncpy()







 //PRENUME

 //CLASA

 //PAROLA

 //NR. MATRICOL


Admini.close();
}
//--------------------------------------------------------------------------- 


Show me wcsncpy() on this code source!
Thanks!
And i'm from romania and i don't speak english very good.

Last edited on Jun 4, 2011 at 8:23am
Jun 4, 2011 at 9:37am
If you are using embarcadero Rad :

Admini>>nume.c_str();


Then you are done :-)
NB: Remember embarcadero Rad 2010 recognizes an AnsiString;

Jun 4, 2011 at 10:15am
not working
next errors:
1)
Cannot convert UnicodeString to wchar_t
2)Structure required on left side of . or, *

the present code is:
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
//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#include <fstream>
#include <iostream.h>
#include <conio.h>
#include <string.h>
#pragma hdrstop
using namespace std;


#include "Cont_nou_elev.h"
#include "Autentificare.h"
#include "Cont_nou_profesor.h"

#include "Directiune.h"
#include "Admin_conturi.h"
#include "Cont_nou.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"






TfrmCont_nou_elev *frmCont_nou_elev;
//---------------------------------------------------------------------------
__fastcall TfrmCont_nou_elev::TfrmCont_nou_elev(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmCont_nou_elev::btnInapoi_cont_nou_elevClick(TObject *Sender)
{
frmCont_nou_elev->Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmCont_nou_elev::btnSalvare_modificari_elevClick(TObject *Sender)

{

				//++++++++++++++++++++++++++++++++++++++++++++++

 ofstream Admini(_T("Admini.dll"), ios::app);


 //CITESTE SI SALVEAZA MODIFICARILE


 // NUME
                                wchar_t *nume =edtNume_elev->Text;

                                Admini>>nume.c_str();


               //  wcsncpy()







 //PRENUME

 //CLASA

 //PAROLA

 //NR. MATRICOL


Admini.close();
}
//---------------------------------------------------------------------------
Topic archived. No new replies allowed.