2DWorlds Forums
System function (C++) - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: Off Topic (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=5)
+--- Forum: Programming (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=30)
+--- Thread: System function (C++) (/showthread.php?tid=8700)



System function (C++) - Dignity - 12-17-2011

Here's what I'm trying to do

Allow users to type in a website (eg google.com) and then use the system function to launch net.exe

I have figured out how to launch net but not how to type cast the string

Google has failed me here


RE: System function (C++) - noob007 - 12-17-2011

It's simple if you're using std:Confusedtring:

Code:
std::string exe = "net.exe ";
std::string webpage = "google.com";
system(exe + webpage);



RE: System function (C++) - Dignity - 12-18-2011

(12-17-2011, 04:10 PM)noob007 Wrote: It's simple if you're using std:Confusedtring:

Code:
std::string exe = "net.exe ";
std::string webpage = "google.com";
system(exe + webpage);

Expect I'm getting user input, where I have to cast it.
But, let me try your idea first.


RE: System function (C++) - noob007 - 12-18-2011

If you're getting user input, you might as well use this:

Code:
std::string exe = "net.exe";

system(exe + USER_INPUT_STRING);



RE: System function (C++) - Dignity - 12-18-2011

Thanks I'll try that zhen I get back



RE: System function (C++) - Dignity - 12-18-2011

(12-18-2011, 12:52 AM)noob007 Wrote: If you're getting user input, you might as well use this:

Code:
std::string exe = "net.exe";

system(exe + USER_INPUT_STRING);

Cannot convert `std::basic_string<char,


RE: System function (C++) - Jacob__mybb_import1 - 12-18-2011

C++ strings are different from C strings, which leads to a lot of confusing bugs like that... It's why I switched to Java. Good luck.


RE: System function (C++) - noob007 - 12-19-2011

(12-18-2011, 11:11 PM)Jacob_ Wrote: C++ strings are different from C strings, which leads to a lot of confusing bugs like that... It's why I switched to Java. Good luck.

You switched to Java just because of the strings? Really? How often do you use strings, anyway?


Anyways, to Roperson, try this:
Code:
std::string exe = "net.exe ";
exe += USER_INPUT;
system(exe.c_str());

Sorry about my previous post.


RE: System function (C++) - Dignity - 12-20-2011

You did it. Big Grin