C ++打开与ShellExecute的链接 [英] C++ open link with ShellExecute
本文介绍了C ++打开与ShellExecute的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我这样写:
ShellExecute(NULL, "open", "www.google.com", NULL, NULL, SW_SHOWNORMAL);
一切都没问题就像它一样。
Everything's okay and is as it has to be.
但我希望用户可以输入他想去的链接。
But I want so that user could enter a link where he wants to go.
std::cout<<"Enter the link: ";
char link;
std::cin>>link;
ShellExecute(NULL, "open", link, NULL, NULL, SW_SHOWNORMAL);
在这种情况下,我得到一个从'char'到'const的无效转换CHAR *
错误。
In this case I get an invalid conversion from 'char' to 'const CHAR*
error.
那么,有没有办法正确地做到这一点?
So, is there a way to do this properly?
推荐答案
您的代码只能获得一个字符作为链接。您需要使链接成为能够保存链接值的类型,并且还要读取stdio。使链接成为std :: string将执行此操作,但是您需要处理它如何传递给ShellExecute
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);
这篇关于C ++打开与ShellExecute的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文