Skip to main content
gamedev.net
🔒 Locked

std::string without std::

Started by flounder 4 replies 1k views
Original Post
flounder
flounder
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?
Evil Steve
Evil Steve
It's , not . If you want to drop the std::, you need to add the line using std::string; or using namespace std; after including the header.
CTar
CTar
The reason made string work is that it includes (any SC++L header may include any other, it's not required to do it though).
nullsquared
nullsquared
string.h (or, in C++, cstring) is a header file that hs C manipulation functions for C-style strings.
flounder
flounder
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;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.