0
I’m trying to make a code to call windows function ping and use output stream to windows file, and while using the code that the program calls on windows console right, but by the program I have a log saying "the file is already being used by another process"
class Archive{
string name;
public:
string getName(){
return this->name;
}
fstream archive;
Archive(string name){
this->name = name;
archive.open(name.c_str(), ios::out | ios::app);
}
};
void ping (Archive &A, string IP){
string command = "ping -t -a ";
command.insert(command.size(), IP);
command.insert(command.size(), " > ");
command.insert(command.size(), A.getName());
A.archive << system(command.c_str());
getchar();
}
int main()
{
Archive A("Ping.txt");
ping(A, "8.8.8.8");
}
Why is this mistake happening? How do I fix it? and how I would do better the sequence I did there
command.insert(command.size(), IP);
command.insert(command.size(), " > ");
command.insert(command.size(), A.getName());```?