c++ - System() function, and calling internet explorer from it, DevC++ -
i tried making program that'd take website info, feed system() start website. i'm aware characters (\, ",') don't fed output directly, used escape sequences.
i wrote program, command prompt refuses go past c:\ path. if copy paste command displayed program, internet explorer gets launched. case isn't program. can tell me error?
here code:
#include<iostream> #include<cstdlib> using namespace std; int main() { cout<<"please enter website wish visit: "; string website,web; cin>>web; web= " " + web; website = "\"%programfiles%\\internet explorer\\iexplore\""+web; cout<<"\n"<<website<<endl<<endl<<endl; system(website.c_str()); return 0; }
pass in double double quotes:
website = "\"\"%programfiles%\\internet explorer\\iexplore\"\""+web; the system("something") call runs command interpreter cmd in way similar (but not identical) cmd /c something. has implications when there spaces in command name, see e.g this. cannot tell why single double quotes work when there's no environment variable involved, , not work otherwise, fact is, double double quotes work.
if want launch user's preferred browser, consider calling
system("start http://" + websitename); instead.
Comments
Post a Comment