0

I get the error E2285 no match found for "system(string) please help me. the code is down below I can't get why it isn't working, for this usuallly works with cout<<

#include <stdio.h>  /* defines FILENAME_MAX */
using namespace std;
#define WINDOWS  /* uncomment this line to use it for windows.*/
#include <direct.h>
#define GetCurrentDir _getcwd
#include <iostream>


string GetCurrentWorkingDir( void ) {
  char buff[FILENAME_MAX];
  GetCurrentDir( buff, FILENAME_MAX );
  std::string current_working_dir(buff);
  return current_working_dir;
}

int main(){
  string dir;
  dir = GetCurrentWorkingDir();
  system("move "+ dir + "\\microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup");
  system("microsoft.html");
  system("cd\\");
  system("cd microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup");
  system("microsoft.exe");

  return 1;
}
halfer
  • 19,824
  • 17
  • 99
  • 186
PY_NEWBIE
  • 77
  • 4
  • you want `std::system` from the `` ? – 463035818_is_not_an_ai Jun 11 '19 at 10:22
  • `system` takes `const char*` as argument, not `std::string`. – Yksisarvinen Jun 11 '19 at 10:28
  • the sequence "move " + dir + "'\..." --> string – AndersK Jun 11 '19 at 10:28
  • 3
    `microsoft.exe`? Suspicious... – Lightness Races in Orbit Jun 11 '19 at 10:30
  • If only all malware authors were this incompetent... – MSalters Jun 11 '19 at 11:36
  • This question was substantially modified after a good answer was given below, and I have thus rolled back to the earlier version. If it is tightly related to this question you could add an **Update** section and put the new code underneath, but I wonder whether in this case, it merits a new question. We generally discourage more than one question in the same post, as it makes it harder to judge answers supplied. – halfer Jun 12 '19 at 18:05
  • Please try to refrain from adding "help please" to questions, especially in titles and especially in shouty case. This will generally be interpreted as begging, and that is not appropriate on a site where a technical writing is preferred. – halfer Jun 12 '19 at 18:07

1 Answers1

1

std::system takes const char* not std::string, which is obvious from the warnings.

system("move "+ dir + "\\microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup")

Here, the result of the sum is std::string. Collect the argument into one single std::string, then use std::string::c_str method to call std::system.

auto arg = "move "+ dir + "\\microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup";
std::system(arg.c_str());

Besides that, you have many errors, like you did not include <string> header, you return 1 from main instead of 0. You use using namespace std;, you use C versions of the standard headers (<stdio.h> instead of <cstdio>), you never included <cstdlib> which defines std::system and so on.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93