Results 1 to 4 of 4
Why is string class not accepted in latest gcc-c++ compiler. Actually I was using Redhat linux 7.1 and had coded using standard string objects. I recently installed Redhat Linux 8.0, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-23-2003 #1Just Joined!
- Join Date
- Dec 2002
- Posts
- 11
why string object not accepted in latest compiler?
Why is string class not accepted in latest gcc-c++ compiler. Actually I was using Redhat linux 7.1 and had coded using standard string objects. I recently installed Redhat Linux 8.0, when I compiled the same code it gave list of errors which was all related to using string objects. It says 'string undeclared'. I have included <string> header in the program.
- 04-23-2003 #2Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
goodtalka,
1. Please don't print everything in bold. It's quite a nasty effect.
2. Exactly which gcc/g++ are you using?
3. I'm betting that if you use anything above 2.95, you'll need to use the namespace in your code.I believe all the newheader files are contained within the namespace std. You can omit the namspace by exclusively attatching std in front of anything from the string class.Code:#include <string> using namespace std; int main() { string = "Ogg Vorbis Rocks!"; return 0; }
Code:#include <string> int main() { std::string name = "This forum is the best!"; return 0; }
The best things in life are free.
- 04-24-2003 #3Just Joined!
- Join Date
- Dec 2002
- Posts
- 11
thankyou, I got it!
But how can I make my code portable for earlier versions of gcc-c++ which doesnot support the namespace concept! I think I should perform some checks before defining namespace! How do I do that?
(All the text is in plain this time(not BOLD) . Is it okay!!
)
- 04-24-2003 #4Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
goodtalka,
Earlier versions of gcc/g++ doesn't care about using namespaces. Well, at least that's what I think. I'm using gcc/g++ 2.95 and at first, I never used namespaces. I even compiled it with the '-Wall' option as I always do and I didn't get any errors about it. To make a long story short, I believe(note this keyword) that only the higher versions will complain if you don't use them. You won't have to worry compatibility when compiling in an earlier version of the compiler. Also, keep in mind that we are only dealing with gcc and g++. There are numerous of compilers out there that may or may not support this. From what I've seen, other compilers want you to use namespacing. In general, just use it. I believe it's a part of ANSI C++.The best things in life are free.


Reply With Quote
