Fail to declare AnsiString

I use Borland C++Builder 3 and I want to use the Length function. Thus, I added two lines at the beginner of the source file:

#include <vcl/dstring.h>
#include <stdio.h>

However, when I press Run, a sysdefs.h windows opened and I receive a error message:

[C++Error] sysdefs.h(427):,expected.


What should I do?

Thank you very much.
saikitAsked:
Who is Participating?
 
jbodomConnect With a Mentor Commented:
If you haven't done so, you need to create a new console application via File New and then select the console option.  Once this is done cut and paste the following code to replace any existing code in the file.  This should give you what you need.


#include <condefs.h>
#include <stdio.h>
#include <conio.h>

#pragma hdrstop

#pragma argsused
int main(int argc, char **argv)
{
    String S="Hello World";
    printf(S.c_str());
    printf("\n");
    printf("%d",S.Length());
    getch();
    return 0;
}
0
 
nietodCommented:
The error message is saying there is a syntax error.  it is expecting a coma.  You probably left out a coma.

We can't tell you anymore than that.  We don't have the code.  
0
 
saikitAuthor Commented:
I haven't put any code in the source, only include two headers and they are provided by the C++Builder.

Should I need to reinstall it or do some config in somewhere?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
nietodCommented:
>> I haven't put any code in the source
ANY?  like the only thing in the source code is the two include lines?  If so that is a problem.  You will need to more in our program.  At the very least you need a main() (or WinMain()) procedure.  If that's not what you meant, sorry to insult you.
0
 
saikitAuthor Commented:
My program is just as below:

#include <vcl/dstring.h>
#include <stdio.h>

void main()
{
printf("Hello World");
}


After pressed Run, the sysdefs.h was open and stop at a line:

typedef SmallStringBase<255> ShortStringBase;  //


The error message is:

[C++Error] sysdefs.h(427): ,expected.
[C++Error] sysdefs.h(428): ,expected.
[C++Error] sysdefs.h(429): ,expected.
[C++Error] sysdefs.h(999): Type name expected.
[C++Error] sysdefs.h(999): Declaration missing ;.
[C++Error] sysdefs.h(1028): 'VString' is not and unambuguous base class of 'System::TVarRec'.
....
....
[C++Error] sysdefs.h(2259): Too many error or warning message.


Please help, I'm new to C++Builder. Thanks.
0
 
wyllikerCommented:
It would seem (I am not familiar with the Builder environment) that you are probably missing some includes that should come before your include of vcl\dstring.h

check the docs or possibly some sample code that might have vcl\dstring.h included and see what that code includes before it.
0
 
nietodCommented:
You probably need to include <windows.h> at the very least.
0
 
nietodCommented:
This is not for VC, it is for builder.

Also he is trying to use the VCL string--AnsiString.

jbodom, it is a good idea to reaqd the question history completely before answering.
0
 
jbodomCommented:
I did read the question history and he answer I proposed is for Borland C++ Builder.  

The AnsiString declaration above may also be used the way I declared it...as String.  When you create a console app in C++ Builder, it (by default) includes the file condefs.h which includes vcl.h.  This will solve his error problem and enable him to use the Length function of AnsiString like he wants.  
0
 
nietodCommented:
Sorry,   I thought that the "#pragma hdrstop" was VC only.  Borland  usually steals only the good ideas of VC, not the bad. I didn't realize that Borladn also supported that.

Then the solution though is to include vcl.h or condefs.h?
0
 
jbodomCommented:
When you create a console app in C++ Builder 3, it gives you the option of whether to use vcl (visual component library).  If you wish to use AnsiString, then you should choose to use vcl when creating the console app.  Once this is done, the code is generated for you and certain compiler options are set that are difficult to set up later if you decide to use vcl.  For a beginner, it is much easier to do it this way.  To just include vcl/dstring.h, you must go to project options and add some include/lib directories as well as other options.  saikit must have just deleted this code or never actually went through the process as I described in a previous message.

Builder does use the #pragma hdrstop directive.  It terminates the precompiled header file list.

The solution then would be to follow the procedure described above.  Does this answer the question?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.