opening a website using strings

so i found this piece of code that will open a website hard coded in the .cpp file i wanted to edit this so it ask's the user "What website do you want to go to?" and then go there. Should i be using different code or can i modify this? in the code i tried replacing "www.google.com" with a string but the function ShellExecute wont take the parameters that way

Thanks



#include<iostream>
#include <windows.h>
#include<string>
using namespace std;

int main()
{
string websiteName;
cout << "What string do you want to open?" <<endl;
cin.clear();
getline(cin,websiteName);

cout << website;

ShellExecute(NULL, L"open", L"www.google.com",NULL, NULL, SW_SHOWNORMAL);


system("pause");
return 0;

}

I imagine that the URL must start with ftp://, http://, or https://.
You can make it so you don't have to type in http:// .



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include <windows.h>
#include<string>
using namespace std;

int main()
{
string szWebSiteExecute;  // sz for good practice. Knows instantly that its a string.
// ^^ szwebstieName + szhttp;
string szwebsiteName;
string szhttp;
szhttp = "http://";
cout << "What website do you want to open?" <<endl;
cin.clear();
getline(cin,szwebsiteName);
szWebSiteExecute = szhttp + szwebsiteName;

cout << szWebSiteExecute;

ShellExecute(NULL, L"open", szWebSiteExecute,NULL, NULL, SW_SHOWNORMAL);


system("pause");
return 0;

}
I didn't compile it, so don't hold be me to it, and I'm not familiar with ShellExecute. I'm kind of just assuming there.
Topic archived. No new replies allowed.