C++ open link with ShellExecute

13,096

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);
Share:
13,096
RnD
Author by

RnD

Struggling

Updated on June 04, 2022

Comments

  • RnD
    RnD almost 2 years

    If I write like this:

        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);
    

    In this case I get an invalid conversion from 'char' to 'const CHAR* error.

    So, is there a way to do this properly?