Sign in to follow this  
charlando

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by charlando
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by charlando
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.


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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
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> <cstring>, which is where they now live. Plain old <string> holds the real std::string.


Fixed [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this