I am trying to make an application on the console and I need to be able to take the input from x and add it to the end of a system as command arguments. It is meant to be the back-end for another console application I am making application Any help would be greatly appreciated. So anyway, here's my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <cstdlib>
#include <iostream>
usingnamespace std;
string x;
int y;
int main()
{
cout << ("This is the website downloader.");
system("set CURRNETDIR=%CD%");
cin >> x;
system("wget.exe") << x;
cout << ("Press 1 when done");
cin >> y;
if(y==1) return 0;
}
system("wget.exe") << x;
This just makes no sense at all. You're trying to use the << operator on whatever gets returned by the function call system("wget.exe").
Break it down into blocks. You need to assemble the string to pass into the system command first, and then pass it in.
As an aside, using system for this is not great. Your OS provides functions designed for you to use to start other programs. Look into using those instead.
It is not defined for objects of type int in this way, which is what the function system returns, and you don't even want to actually apply it to the returned value of the function; you want to apply it to the parameter you're going to pass in to the function.
In short, << is very inappropriate for this :) Applied to an int, it is the bitshift operator. Completely different.
I just want add the input on to the end of the command within the system input is there a simple way to do this?
Didn't I already answer this? It doesn't get much simpler than this. I'll add comments to explain it.
1 2 3 4 5 6 7 8 9 10 11 12 13
// Make a string. This is the start of what we will pass to system
string theStringToPassToSystem = "wget.exe";
// Get the user input
cin >> x;
// add that to the end of the string we already have
theStringToPassToSystem = theStringToPassToSystem + x;
// pass it to system. system doesn't like proper strings, it likes pointers to char,
// so we have to use the string function c_str() to make the string into a
// pointer to char
system(theStringToPassToSystem.c_str());