Jump to content
  • Advertisement
Sign in to follow this  
charlando

std::string problem

This topic is 4356 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

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
Advertisement
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
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!