How to use CMD command in C ++?

I want to use this cmd command

ROBOCOPY D:\folder1 D:\folder2 /S /E

with conditions for copying the contents of folder1 to folder2

if(i == 1)

and

if(i == 2)

ROBOCOPY D:\folder3 D:\folder4 /S /E

to copy the contents of folder3 to folder4

what should I do?

-2
source share
2 answers

"what should I do?"

You just do it (using ): std::system()

#include <cstdlib>

// ...

if(i == 1) {
    std::system("ROBOCOPY D:/folder1 D:/folder2 /S /E");
}
else if(i == 2) {
    std::system("ROBOCOPY D:/folder3 D:/folder4 /S /E");
}

, , "D:\folder3", '\', '\': "D:\\folder3".
, ( windows , ): "D:\\\\folder3".
, '/', .

+1

All Articles