1
In order to automate some backups that need to be done routinely, so I thought of using an dos
to do, but I’m having trouble compiling the executable because it seems to me that the function
only accepts char variables, the code I used was the following.system()
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
string usuarios[5] = {"usuario","usuario","usuario","usuario","usuario"};
string diretorios[5];
string path[28];
for (int i = 0; i < 5; ++i) {
diretorios[i] = "mkdir c:\\backups\\"+usuarios[i];
system(diretorios[i]);
path[i] = "c:\\unisystem\\backup\\"+usuarios[i];
system("exp system/abcd owner="+usuarios[i]+" file="+path[i]+"\\"+usuarios[i]+".dmp log="+path[i]+"\\"+usuarios[i]+".log compress=n");
}
cout << "O processo de backup terminou!"<< endl;
system("pause");
return 0;
}
there is another function I can replace the system()
or I have to convert string to char?
It worked Thank you! But then you mean that I reference the text variable information by the memory address it is occupying? So I don’t have to convert the guys?
– Jean Freitas
It’s not converting, it’s just pointing. The pointer that
c_str()
returns, rather represents the location where the characters are, but when you use it the way I showed it, you’re "slipping" it, using it as a normal C string. If you want to display the memory address, then you would have to convert the pointer itself:std::cout << static_cast<void*>(&minhaString[0]);
– Ossetian_Odin