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

7 Years
Discussion Span
Last Post by vijayan121
Featured Replies

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";	

@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.

Edited by Sky Diploma: n/a


@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.

Votes + Comments

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?)

Edited by vijayan121: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.