Jump to content
  • Advertisement
Sign in to follow this  
monkey4sale

SDL BMP loading

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

I have started work on a project of my own trying to make an easily moddable RPG, I decided to use text documents to store the information for rooms, items, and image locations, but I have run into a snag while trying to get the string read from the file to be accepted by the SDL_LoadBMP function. the error report is this: /media/disk/Programming/C++ Projects/AdventureGame/main.cpp|76|error: cannot convert 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to 'const char*' for argument '1' to 'SDL_RWops* SDL_RWFromFile(const char*, const char*)'| /////////////////////////////////////////////////////////////////////////////// I am trying to load the information from the file like this: // uses the iStream1 file stream to open the main text file iStream1.open("main.txt", ios::in); // Sends the file stream into the text string and loops through until an EOF while(getline(iStream1,text)) { // tracks the total amount of lines line++; //Outputs the unmodified text //cout << text << endl; //Finds the number of the current image loc = text.find(":"); // Finds the number in the string subtext = (text.substr(0,loc)); // Converts the string number into an integer i = boost::lexical_cast<int>(subtext); //Stores to the map Images = text.substr(loc+1,text.size()); // Outputs the number derived with boost //cout << i << endl; } ////////////////////////////////////////////////////////////////////////////// line is an int, loc is an int, subtext is a string, i is an int, Images is a map<int,string> As far as I understand what this should do is: retrieve one line from iStream1 and store it into text, increment line, find te location of a colon and store that location in loc, get the sub string in between the beginning of the stream and loc since that should be a number, convert the sub string into a number using the boost library, create a new entry in the map using i as the key and the substring found after the colon as the value. And it does seem to do that, what is wrong with the SDL bmp function that wont allow a string?

Share this post


Link to post
Share on other sites
Advertisement
You're sending it a C++ string, AKA std::string. SDL is a C API, and hence uses regular C-strings (which are just arrays of char's). This is why the documentation specifies that the parameters is a pointer to a char, and why the compiler complains that it can't convert from type "std::string" to "const char*". However the string class provides a function that returns a pointer to a C-string, called "c_str()". Just call that and send the result to SDL_LoadBMP.

Share this post


Link to post
Share on other sites
Never mind I fixed it, problem was an additional line, it was blank so I didnt notice it....

Thanks for the help

[Edited by - monkey4sale on August 20, 2008 5:54:42 PM]

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!