# std::string problem

## Recommended Posts

As i so recently joined and got SDL working (yay), i've been following some tutorials. The one problem that remains is as:
Quote:
 main.c:24: error: string' is not a member of std' main.c:25: error: expected ,' or ;' before '{' token
and the code of lines 24-25 is:
Quote:
 SDL_Surface *load_image( std::string filename ) {
Any help is apreciated as always, ty.

##### Share on other sites
Are you including the string header file?

#include <string>

##### Share on other sites
First observation, you probably shouldn't be using the extension '.c' for a C++ file as it's conventionally used for C.

Also, kind of the obvious question: are you including <string>?

- o

##### Share on other sites
yes i am including - #include <string.h> - and thanks for pointing out the file extension, but it didn't change anything. I'm still getting the same error.

EDIT: strangly, i just changed <string.h> into <string> and it worked 0_o
why is that so?

##### Share on other sites
You are supposed to include <string> without the .h

##### Share on other sites
You should be doing
#include <string>

If your tutorial or whatever is telling you to include <string.h> it is out of date. :)

##### Share on other sites
Quote:
 Original post by charlandoyes i am including - #include - and thanks for pointing out the file extension, but it didn't change anything. I'm still getting the same error.

string.h is deprecated. Just #include <string>. That might be why it can't find string in the std namespace.

EDIT:
Man, I'm slow today.

##### Share on other sites
Quote:
 Original post by charlandoyes i am including - #include - and thanks for pointing out the file extension, but it didn't change anything. I'm still getting the same error.

string.h is c's libraries header for manipulating c-style strings.

You want to try and #include <string>. There is no extension on the standard c++ library header files.

##### Share on other sites
ok, thankyou for your help, it is most apreciated. So kind, you all are :)

##### Share on other sites
string.h is a different thing altogether. It contains C 'string' manipulation functions like strcat, strlen etc.

But if for some reason you need those in a C++ program anyway, you should instead include <string>, which is where they now live. Plain old <string> holds the real std::string.

##### Share on other sites
Quote:
 Original post by Zahlmanstring.h is a different thing altogether. It contains C 'string' manipulation functions like strcat, strlen etc.But if for some reason you need those in a C++ program anyway, you should instead include , which is where they now live. Plain old holds the real std::string.

Fixed [smile]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35