Sign in to follow this  
monkey4sale

SDL BMP loading

Recommended Posts

monkey4sale    127
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[i] = 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
MJP    19786
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
monkey4sale    127
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

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