C++ open link with ShellExecute

主宰稳场 提交于 2019-12-02 01:25:51

Your code only gets one character in as the link. You need to make link a type able to hold the value of the link and also read stdio in. Making link a std::string will do this but then you need to take care of how it is passed to ShellExecute

std::cout<<"Enter the link: ";
std::string link;
std::cin>>link;
ShellExecute(NULL, "open", link.c_str(), NULL, NULL, SW_SHOWNORMAL);

You should declare your input as char*

char *link = new char[2048];

...
delete[] link;

The const char* in ShellExecute is just a promise that it won't change the input. After changing the declaration, everything should work as expected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!