Home > Back-end >  Turn a string in c Builder gibberish
Turn a string in c Builder gibberish

Time:09-22

Because the work needs, with a program changes to the text files, because the interface assignment is string properties, and text file to read the fgets () function () parameter must be a character array, therefore with code written text, writing is as follows:
1.
UnicodeString Db=cxDBTextEdit59 - & gt; The Text;
//assume that string for "because of work demand, with a program changes to the text file" the words;
AnsiString Cstr=Db;//I don't understand why we have to use the UnicodeString instead of the previously AnsiString,

Char SCH [64].
Int I, j;

J=Cstr Length ();//

for(i=0; i{
SCH [I]=Cstr [I + 1);//the first subscript AnsiString starting from 1, the array from zero beginning,
}
Fprintf (px, "% s", SCH);///

2. The UnicodeString Db=cxDBTextEdit59 - & gt; The Text; ;

Char * cp=new char [Cstr. Length () + 1);

__try
{
Strcpy (cp, Cstr c_str ());
Fprintf (px, "% s", SCH);///
}
__finally
{
The delete [] cp;
}
The above results are unable to open the text file, use the viewer found that both methods assignment for gibberish, hope the great god help answer, thank you!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

Should be no problem, in the second, for example:
UnicodeString Db=Edit1 - & gt; The Text;
The FILE * p=fopen (" temp. TXT ", "w");
AnsiString Cstr=Db;
Char * cp=new char [Cstr. Length () + 1);
__try
{
Strcpy (cp, Cstr c_str ());
Fprintf (px, "% s", cp);//not SCH
}
__finally
{
The delete [] cp;
}
The fclose (px);

CodePudding user response:

Thank you upstairs, but are wrong clew, assignment in executable program are garbled

CodePudding user response:

You should make sure what's your text file format, text files are ASCII or unicode,,

CodePudding user response:

reference draculamx reply: 3/f
you should make sure what's your text file format, text files are ASCII or unicode,,


Thank you, I'll get it

CodePudding user response:

The essence of the original poster to understand the Unicode and ASCII,
C + + builder to support multiple languages, all of the string interface controls access to say, in the form of a Unicode
For example
UnicodeString STR="123"; Here for the two actions, the "123" turned Unicode characters, and then copy into the STR,

Your writing is wrong, the correct wording should be like this,
UnicodeString Db=cxDBTextEdit59 - & gt; The Text;
AnsiString Cstr=Db. T_str (). (if your compiler is more than 2009 version!!! )

CodePudding user response:

In addition,
The following c + + builder2007
All interface Text String is equal to the AnsiString is ascci

C + + more than builder2010
String is equal to the UnicodeString, all of the Text interface is unicode

CodePudding user response:

Turn ascci Unicode

AnsiString cStr="123";
UnicodeString uStr=cStr;//the default help you turn the

AnsiString cStr2=uStr. T_str (); Manually turn
  • Related