Opening specific link in c++ program

How can I open a link using the input that the user gave in a c++ program? For example I want to ask the user to enter their facebook name/youtube channel name etc and the program to open facebook/(input), youtube/(input) etc. I only found solutions to if I wanted to open a link that the user typed in, but not a link that is modified based on what the user puts in. Thanks in advance!
One way would be to define a base url and then add the user name to it.

For example:

1
2
3
4
5
6
7
8
9
10
11
12

string baseUrl = "https://www.facebook.com/"; 
// or https://www.youtube.com/user/ for YouTube

string userName;

cout << "Username: ";
cin >> userName;

string completeUrl = baseUrl + userName;

// TODO open the completeUrl somehow - maybe ShellExcute or sth. else 
Hey, thanks for the reply! My code now looks like this and works as intended!


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 <string>

using namespace std;

int main() {
string site;
cout << "Enter Desired site: " << endl;
cin >> site;
string baseUrl;
if(site=="Facebook"){
	baseUrl="https://www.facebook.com/";
	cout << baseUrl << endl;
}
else if(site=="Youtube"){
	baseUrl="https://www.youtube.com/user/";
	cout << baseUrl << endl;
}
cout << "Enter Username: " << endl;
string username;
cin >> username;

string completeUrl=baseUrl+username;
system(std::string("start " + completeUrl).c_str());
	return 0;
}
Last edited on
Topic archived. No new replies allowed.