is there a way of using or declarin string objects without using
#include <string>
using std::string; ?????????????

NO

was wondering myself!...saw the question in some book n av bin ponderin over it

This compiles in visual studio 2008 express edition:

#include <iostream>
using namespace std;
int main(){	
	string name = "lol";	
}

@firstPerson: That's just because <string> is probably included by <iostream>.

However, Technically its possible if you write your own "string" class and place it in a std namespace :D

@SkyDiploma: Man.. you are evil!
@racoon: Stay away from the evil temptation of making your own class named string in the std namespace.. if there is a Hell for programmers this will certainly send you there.

@firstPerson: That's because YOUR compiler lets you do that. vc++ 2010 will not.

@Sky: You still have to include the header file for your version of the string slcass. So its not even "technically possible". You need to include the string header file regardless of whose class it is (or put your class declaration in the *.cpp file that uses it)

@mike: Hehe :).
@racoon: What mike said is absolutely true.
@AD: Thats exactly What I meant. put the declarations in the *.cpp file and it'll work.

@Sky: But that's not answering the OP's question. I think he wants to use the string class that's in STL. Writing your own isn't the same thing, nor would it even be desireable outside the adademic area of a university.

@AD: <string> is technically part of the C++ standard library, not the C++ standard template library (STL), these are two distinct libraries.

commented: right +31

@mike: You're right of course, as always.

after all said and done i think its jst advisable to stick with #include <string>,...and i agree writing a saparate string class can be a bad idea

> Thats exactly What I meant. put the declarations in the *.cpp file and it'll work.

For starters, that will be a gross violation of ODR. see: http://en.wikipedia.org/wiki/One_Definition_Rule

You could of course write your own string class, and use it in any way that you please, as long as you don't put it into the namespace std. (Or if you do not use anything from the namespace std anywhere in your entire program; very difficult indeed - how do you get rid of std::bad_alloc?)

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.