Currently I'm attempting to get a webpage that the user inputs using a system call. However I can't get the system call with the user's inputted website working.
My program looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <string>
int system(constchar *command);
int main()
{
string website;
cout<<"Enter a website that you want to grab: ";
cin>>website;
int get=system ("wget "+website);
return get;
}
Tell me more about your problem. Is it not compiling? If it compiled correctly, what happens when you run it? Does it crash, hang, or just display nothing?
It seems as though system() won't accept a string as an argument- you must supply a pointer to a const char. That's fine- we'll use c_str() to convert the string to a c-style string, and then cast it into a const char*.
1 2 3 4 5 6 7 8
int main()
{
std::string website;
std::cout<<"Enter a website that you want to grab: ";
std::cin>>website;
std::string command = "wget " + website;
system((constchar*)command.c_str());
}