问题是在Wt中我无法从我的电脑下载本地文件,我可以从互联网下载文件,请帮我解决这个问题...
这是源代码:
#include "headers.h"
std::string readFileToString(const std::string &filePath) {
std::ifstream file(filePath);
std::stringstream buffer;
buffer << file.rdbuf();
return buffer.str();
}
class Application : public Wt::WApplication
{
public:
Application(const Wt::WEnvironment &env);
private:
bool isClicked = true;
};
Application::Application(const Wt::WEnvironment &env) : WApplication(env)
{
this->setTitle("App");
this->doJavaScript(std::async(std::launch::async | std::launch::deferred,
readFileToString,
"D:/web/script.js"
).get());
auto image = this->root()->addWidget(std::make_unique<Wt::WImage>(""));
image->setAttributeValue("src", "icons/image.png");
image->setAttributeValue("alt", "image");
image->setId("main-image");
}
int main(int argc, char **argv)
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
auto app = std::make_unique<Application>(env);
return app;
});
}
它不加载图标/图像 图片.png:1
浏览器中显示的内容如下: 获取 http://127.0.0.1:8000/icons/image.png 404(未找到)