fork was not declared in this scope

#include <iostream>
#include <unistd.h>

int main() {
    pid_t pid = fork();

    if (pid == -1) {
        // Handle error
        std::cerr << "Fork failed!" << std::endl;
        return 1;
    } else if (pid > 0) {
        // Parent process
        std::cout << "This is the parent process. Child PID: " << pid << std::endl;
    } else {
        // Child process
        std::cout << "This is the child process. PID: " << getpid() << std::endl;
    }

    return 0;
}