On windows, you can use this
#include <windows.h>
string getPath() {
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
then write
Image img;
img.loadFromFile(getPath() + "\\myImg.png");
On windows, you can use this
#include <windows.h>
string getPath() {
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
then write
Image img;
img.loadFromFile(getPath() + "\\myImg.png");
Thanks for this answer, although Im slightly hesitant as I would have thought there was a more concise way of doing it.
You could do
chdir("dir/holding/resources");
img.loadFromFild("myfile.png");