Jump to content
  • Advertisement
Sign in to follow this  
flounder

std::string without std::

This topic is 4427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is the string class dependant on iostream? when i call std::string in a project without iostream, i get the error "string is not a member of std". When i remove the std::, i get the error "string undeclared". I want to take iostream out of my project because of the ~300k it adds to the executable. example:
#include <cstdlib>
//#include <iostream>
#include <string.h>

int main(int argc, char *argv[])
{
	/*std::*/string me("hello");
	system("PAUSE");
	return EXIT_SUCCESS;
}


Is there a way of using the string class without iostream included in the project?

Share this post


Link to post
Share on other sites
Advertisement
It's <string>, not <string.h>. If you want to drop the std::, you need to add the line using std::string; or using namespace std; after including the header.

Share this post


Link to post
Share on other sites
No, it is not related to std::iostream. Everything in the C++ standard is in the std scope (when possible). The include file for std::string is <string> not <string.h>.

Share this post


Link to post
Share on other sites
The reason <iostream> made string work is that it includes <string> (any SC++L header may include any other, it's not required to do it though).

Share this post


Link to post
Share on other sites
I didn't know i've been including the wrong header all this time. The following code works good for me, thanks for the help!


#include <cstdlib>
#include <string>

using std::string;

int main(int argc, char *argv[])
{
string me("hello");
system("PAUSE");
return EXIT_SUCCESS;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!