• Advertisement
Sign in to follow this  

std::string without std::

This topic is 4250 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
string.h (or, in C++, cstring) is a header file that hs C manipulation functions for C-style strings.

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