Say that I am making aprogram in c++ that opens a web page through the use of a system command and I want the user of the program to type in the website they want using the cin operator. How would I use the variable holding the web address in the system command? Would I do somthing like this: system("start" websitevariable) ? Please include the whole source code file.
How do I include a variable value in a system command in c++?
You would need to use the strcat() function from the %26lt;cstring%26gt; header.
system(strcat("start ", webSiteVar));
However... calls to the shell (using system()) is a very, very bad habit and it's just a terrible habit... consider that you can pipe several commands in one line... for instance, what would happen if I were to do this?
webSiteVar = "http://www.google.com | echo Y | del *.*";
system(strcat("start ", webSiteVar));
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment