Star a website

I need help.

I am trying to make the console star a website. I want to make It so you type in a website and then It starts it up.

1
2
3
4
5
6
if (URL == 3){ 
			string Search; 
			cout << "Enter URL: "; 
			cin >> Search; 
			cout << "\nStarting: " << Search; 
			system("start Search");}


I can't get system to recognize Search as a data type and not a word.

I bet the answer is real simple but I can't figure it out.
Last edited on
You're not making a lot of sense. On your operating system, in a command window, what does typing in this do?

start www.google.com


That's what you seem to be trying to automate.
Last edited on
I want to be able to have someone enter a website and have the console start the website.
So...instead of someone running the browser and typing in the URL, you're making a C++ program that the user has to run, type in the URL and then have your program load the browser?

Anyways, to fix your problem: system("start /* Web Browser.exe */ " + URL);

Now it's up to you to figure out the exact syntax on how to open your browser.
When I do that is says
error C2664: 'system' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const char *'


but when I did it, I changed
URL
to Search
Last edited on
ugh...
system("start browser.exe " + URL.c_str());
When I do that it says
error C2228: left of '.c_str' must have class/struct/union
I dont think that you can recognize Search as a data type (not sure) but you can write the command in a file (*.cmd)
for ex
1
2
3
4
5
6
  ofstream myfile;
  cin >> Search
  myfile.open ("example.cmd");
  myfile << "start";
  myfile << Search;
  myfile.close();
No I want to do it from c++
1
2
3
4
5
string website;
cin >> website;
string finalCommand = "C:/some/directory/to/your/browser/browser.exe ";
finalCommand = finalCommand + website;
system(finalCommand.c_str());
Ill try it soon. I'm working on something else right now.
Thank you Moschops, I couldn't think about why it wasn't working.
Moschops, it gives no errors but it won't start a website.
Try
1
2
3
4
5
string website;
cin >> website;
string finalCommand = "start C:/some/directory/to/your/browser/browser.exe ";
finalCommand = finalCommand + website;
system(finalCommand.c_str());

Also for what its worth on my system (Windows 7 64) this opens my default browser (or new tab if open)
1
2
3
std::string site = "www.google.com";
	site = "start "+site;
	system(site.c_str());
Thank you that worked.
Topic archived. No new replies allowed.