943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1566
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 17th, 2008
0

Can't use Strings :'(

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Risame is offline Offline
8 posts
since Aug 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

Try using the fully qualified name to make sure you've made the namespace visible for the <string> header:
C++ Syntax (Toggle Plain Text)
  1. std::string q;
Reputation Points: 361
Solved Threads: 97
Posting Pro
Radical Edward is offline Offline
526 posts
since May 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Aug 17th, 2008
0

Re: Can't use Strings :'(

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

C++ Syntax (Toggle Plain Text)
  1. 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Risame is offline Offline
8 posts
since Aug 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

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 ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Risame is offline Offline
8 posts
since Aug 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

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++.
Reputation Points: 361
Solved Threads: 97
Posting Pro
Radical Edward is offline Offline
526 posts
since May 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

Try this program:

C++ Syntax (Toggle Plain Text)
  1. // HelloWorld.cpp
  2.  
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. cout << "Hello World" << endl;
  9. return 0;
  10. }

See if you get any errors. You shouldn't.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

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:

C++ Syntax (Toggle Plain Text)
  1. #include <string>
  2. using namespace std;

Reputation Points: 10
Solved Threads: 0
Newbie Poster
Risame is offline Offline
8 posts
since Aug 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

Click to Expand / Collapse  Quote originally posted by Risame ...
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)
  1. #include <string>
  2. 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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Aug 17th, 2008
0

Re: Can't use Strings :'(

Try this program:

C++ Syntax (Toggle Plain Text)
  1. // HelloWorld.cpp
  2.  
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. cout << "Hello World" << endl;
  9. return 0;
  10. }

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:

C++ Syntax (Toggle Plain Text)
  1. // HelloWorld.cpp
  2.  
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9. cout << "Hello World" << endl;
  10. return 0;
  11. }
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Random Change Between
Next Thread in C++ Forum Timeline: About the modulo operator





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC