Can't use Strings :'(

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 8
Reputation: Risame is an unknown quantity at this point 
Solved Threads: 0
Risame Risame is offline Offline
Newbie Poster

Can't use Strings :'(

 
0
  #1
Aug 17th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: Can't use Strings :'(

 
0
  #2
Aug 17th, 2008
Try using the fully qualified name to make sure you've made the namespace visible for the <string> header:
  1. std::string q;
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Can't use Strings :'(

 
0
  #3
Aug 17th, 2008
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: Risame is an unknown quantity at this point 
Solved Threads: 0
Risame Risame is offline Offline
Newbie Poster

Re: Can't use Strings :'(

 
0
  #4
Aug 17th, 2008
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

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: Risame is an unknown quantity at this point 
Solved Threads: 0
Risame Risame is offline Offline
Newbie Poster

Re: Can't use Strings :'(

 
0
  #5
Aug 17th, 2008
Originally Posted by Ancient Dragon View Post
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 ?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: Can't use Strings :'(

 
0
  #6
Aug 17th, 2008
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 at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,817
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Can't use Strings :'(

 
0
  #7
Aug 17th, 2008
Try this program:

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: Risame is an unknown quantity at this point 
Solved Threads: 0
Risame Risame is offline Offline
Newbie Poster

Re: Can't use Strings :'(

 
0
  #8
Aug 17th, 2008
Originally Posted by Radical Edward View Post
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:

  1. #include <string>
  2. using namespace std;

Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,817
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Can't use Strings :'(

 
0
  #9
Aug 17th, 2008
Originally Posted by Risame View Post
If that's the case what can I do ?

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

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,817
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Can't use Strings :'(

 
0
  #10
Aug 17th, 2008
Originally Posted by VernonDozier View Post
Try this program:

  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:

  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. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC