Hi everyone, I'm new and hope someone can help with my problem. First of all English is not my first languaje so I hope you all can be a little patient with my writing :icon_cheesygrin:

Here's the thing. I'm new to C++, and I'm using Borland 3.1 (this is the teacher's choice so I prefer to work with this compiler, because I will have to use it for the tests), and I simply haven't been able to work with Strings. I have tried these 3 "includes" (I don't really know how they are called :?: ),

#include <string> The compiler gives me an error when I use this one
#include <string.h> No problem when compiling
#include <CString> No problem when compiling

But when I put

string q; or
CString q;

The compiler gives me this 2 errors:

"Undefined symbol 'string' (or 'CString' depending of which one I'm using)" and
"Statement misssing ;"

Any idea? :(

Recommended Answers

All 18 Replies

Try using the fully qualified name to make sure you've made the namespace visible for the <string> header:

std::string q;

what compiler and os are you using? Are you trying to compile a C file with *.c extension?

The only CString class I know of is in Microsoft's MFC library.

Sorry I didn't put the code between the [code] [/code] thing, I am really in a hurry with this thing and didn't pay attention. I tried to fix my last post but couldn't find an "edit" button :S

I tried what you said, and It gives me this error: "Typer qualifier 'std' must be a struct or class name"

I don't know if this error is related with the fact that I am not using the line

using namespace std;

This is because this instruction gave me this error : "Declaration syntax error" . I read that this line was necessary for the instruction "cout" to work, but I eliminated it, and I can use the "cout" without a problem.

what compiler and os are you using? Are you trying to compile a C file with *.c extension?

The only CString class I know of is in Microsoft's MFC library.

I'm using Windows XP and Borland 3.1.

About the other question, the file's name ends in .CPP, is that what you are asking me ?

It looks a lot like you're either using a really old C++ compiler, or you're compiling your code as C instead of C++.

Try this program:

// HelloWorld.cpp

#include <string>
using namespace std;

int main ()
{
    cout << "Hello World" << endl;
    return 0;
}

See if you get any errors. You shouldn't.

It looks a lot like you're either using a really old C++ compiler, or you're compiling your code as C instead of C++.

If that's the case what can I do ?

To VernonDozier: It gives me an error with this two lines:

#include <string>
using namespace std;

:(

If that's the case what can I do ?

To VernonDozier: It gives me an error with this two lines:

#include <string>
using namespace std;

:(

I know nothing about Borland and how to check what compiler you are using and how to configure it, but there must be a way. If you are accidentally using a C compiler, you'll get those errors. make sure the file extension of your source file is not .c but is rather something like .cpp. There's usually some option where you can figure out what compiler is being used and change it if necessary, but like I said, not knowing Borland, I don't know where that option would be.

I'd ditch the compiler altogether though and ask your professor if he/she is willing to teach the class using something more modern. It's about 15 years old. There are a lot of free modern ones available.

Try this program:

// HelloWorld.cpp

#include <string>
using namespace std;

int main ()
{
    cout << "Hello World" << endl;
    return 0;
}

See if you get any errors. You shouldn't.

Heh heh. Simple Hello World program and I screw it up. You have to #include <iostream>. Still you should not have gotten those errors and thus you're likely accidentally compiling in C. Corrected program below:

// HelloWorld.cpp

#include <iostream>
#include <string>
using namespace std;

int main ()
{
    cout << "Hello World" << endl;
    return 0;
}

Yes the file's name ends with .cpp

One question. I know that this program (Borland), works without a problem at my university, so can I simply work here at may house with any other program, and then go there and Copy&Paste the code in Borland? Will there be any problem?

BTW Yes I had the #include <iostream> when I compiled the program, And it still gave those errors.

Yes the file's name ends with .cpp

One question. I know that this program (Borland), works without a problem at my university, so can I simply work here at may house with any other program, and then go there and Copy&Paste the code in Borland? Will there be any problem?

Seems like that would work. You can try Dev C++ or Code Blocks or Visual Studio Express. All are free and modern.

http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments

Well guess I will have to do that, can't see any other way. I have spent like two days trying to make this work, and I guess I have had enough ^^

Thank you all for your help, hope my bad English hasn't been a problem ;)

That ancient Borland compiler probably wants <iostream.h> and leave out the using namespace std; statement.

Well guess I will have to do that, can't see any other way. I have spent like two days trying to make this work, and I guess I have had enough ^^

Thank you all for your help, hope my bad English hasn't been a problem ;)

Off topic: You actually type better English than some people who have lived in America for over 40 years...

As far as I know no namespaces and string class (no STL at all) in BC++ 3.1. Old streams implementation via <iostream.h> - that's all...

Off topic: You actually type better English than some people who have lived in America for over 40 years...

Haha thanx ^^

Just for you to know, I talked with my professor and asked him if there was a way for using Strings witn Borland, and he said to me that no there isn't, that that was one of the reasons for chossing that program...

Now I have wasted 2 days trying to figure out something that did't have solution, and looks like he wants us to create our own String Class O.o . What a great start...

What a great start...

Don't think that way. Think about how much you've learned through all of the troubleshooting. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.