| | |
Can't use Strings :'(
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
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
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?
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?
Try using the fully qualified name to make sure you've made the namespace visible for the <string> header:
C++ Syntax (Toggle Plain Text)
std::string q;
If at first you don't succeed, keep on sucking until you do succeed.
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
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 
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
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.

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
C++ Syntax (Toggle Plain Text)
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.
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
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.
About the other question, the file's name ends in .CPP, is that what you are asking me ?
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
Try this program:
See if you get any errors. You shouldn't.
C++ Syntax (Toggle Plain Text)
// HelloWorld.cpp #include <string> using namespace std; int main () { cout << "Hello World" << endl; return 0; }
See if you get any errors. You shouldn't.
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
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++.
To VernonDozier: It gives me an error with this two lines:
C++ Syntax (Toggle Plain Text)
#include <string> using namespace std;
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
•
•
•
•
If that's the case what can I do ?
To VernonDozier: It gives me an error with this two lines:
C++ Syntax (Toggle Plain Text)
#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.
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
•
•
•
•
Try this program:
C++ Syntax (Toggle Plain Text)
// HelloWorld.cpp #include <string> using namespace std; int main () { cout << "Hello World" << endl; return 0; }
See if you get any errors. You shouldn't.
C++ Syntax (Toggle Plain Text)
// HelloWorld.cpp #include <iostream> #include <string> using namespace std; int main () { cout << "Hello World" << endl; return 0; }
![]() |
Similar Threads
- Comparing Strings in C# (C#)
- Please help me compare strings (Java)
- reversing two strings (C)
- C++ handling of strings in a boolean expression (C++)
- Compare strings... (C++)
- comparing two strings with linear search.. (Java)
- JSP and Oracle (JSP)
Other Threads in the C++ Forum
- Previous Thread: Random Change Between
- Next Thread: About the modulo operator
Views: 1297 | Replies: 18
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






