I don’t know the SFML in depth, but because it is a library for access to multimedia resources I believe it has no resources to facilitate the request of the file name to the user (or at least it must be very difficult to build it using the class Window
).
An alternative is to use a graphical library such as Qt. You could build your own graphical interface for this, but it is quite common (and facilitates the use of users accustomed to the operating system) to utilize the standard file selection window.
With Qt you can do it this way:
#include <QFileDialog>
QString arquivo = QFileDialog::getOpenFileName(this, "Abrir imagem", ".", "Arquivos PNG (*.png);; Todos os arquivos (*.*)"));
if(arquivo.length())
{
sf::Image imagem;
if (!imagem.loadFromFile(arquivo.toStdString())) {
cout<<"Erro ao abrir a imagem!"<<endl;
}
}
This code will open a file selection window like the one below (example reproduced of that OS thread in English - I didn’t get to execute the code here), where the user can select the existing file or even type the path. By clicking the OK button (the image is in another language, but it doesn’t matter), the window is closed and the method QFileDialog::getOpenFileName
returns a string with the path and name of the selected file. Just use it in the `Image::loadFromFile' method of the SFML library, as illustrated above.
Your question is not very clear. It seems that the question is about how to ask the user to choose a file, not how to open a C++ image with SFML. That’s it?
– Luiz Vieira