Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
System function (C++)
#1
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
Reply
#2
It's simple if you're using std:Confusedtring:

Code:
std::string exe = "net.exe ";
std::string webpage = "google.com";
system(exe + webpage);
Reply
#3
(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.
Reply
#4
If you're getting user input, you might as well use this:

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

system(exe + USER_INPUT_STRING);
Reply
#5
Thanks I'll try that zhen I get back
Reply
#6
(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,
Reply
#7
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.
Reply
#8
(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.
Reply
#9
You did it. Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)