To create a C++ program that connects to a PostgreSQL database, retrieves data from multiple tables using JOIN operations, and outputs the results in a formatted table, you will need to use a library like libpqxx. Here's an example of how to do this:

1. First, install the libpqxx library on your system. You can find instructions for installing it here: https://github.com/jtv/libpqxx

2. Create a new C++ file (e.g., main.cpp) and include the necessary headers:

```cpp
#include <iostream>
#include <iomanip>
#include <pqxx/pqxx>

using namespace std;
using namespace pqxx;
```

3. Inside the `main` function, establish a connection to the PostgreSQL database:

```cpp
int main() {
    try {
        connection conn("dbname=your_database user=your_user password=your_password hostaddr=127.0.0.1 port=5432");
        if (conn.is_open()) {
            cout << "Connected to database successfully!" << endl;
        } else {
            cerr << "Cannot connect to database." << endl;
            return 1;
        }
```

Replace `your_database`, `your_user`, and `your_password` with the appropriate values for your PostgreSQL setup.

4. Execute a SQL query that performs a JOIN operation between two tables:

```cpp
        // Replace these table names and column names with your own
        string tableName1 = "table1";
        string tableName2 = "table2";
        string columnName1 = "column1";
        string columnName2 = "column2";

        work txn(conn);
        result res = txn.exec("SELECT " + tableName1 + "." + columnName1 + ", "
                              + tableName2 + "." + columnName2 +
                              " FROM " + tableName1 +
                              " JOIN " + tableName2 +
                              " ON " + tableName1 + ".id = " + tableName2 + ".id");
        txn.commit();
```

5. Output the results in a formatted table:

```cpp
        cout << left << setw(20) << columnName1 << setw(20) << columnName2 << endl;
        cout << string(40, '-') << endl;

        for (const auto &row : res) {
            cout << left << setw(20) << row[0].c_str() << setw(20) << row[1].c_str() << endl;
        }
    } catch (const exception &e) {
        cerr << e.what() << endl;
        return 1;
    }

    return 0;
}
```

6. Compile and run your program:

```bash
g++ -std=c++11 main.cpp -lpqxx -lpq -o main
./main
```

This example assumes you have two tables with an `id` column that can be used to join them. Replace the table names and column names with your own values.

The complete code should look like this:

```cpp
#include <iostream>
#include <iomanip>
#include <pqxx/pqxx>

using namespace std;
using namespace pqxx;

int main() {
    try {
        connection conn("dbname=your_database user=your_user password=your_password hostaddr=127.0.0.1 port=5432");
        if (conn.is_open()) {
            cout << "Connected to database successfully!" << endl;
        } else {
            cerr << "Cannot connect to database." << endl;
            return 1;
        }

        // Replace these table names and column names with your own
        string tableName1 = "table1";
        string tableName2 = "table2";
        string columnName1 = "column1";
        string columnName2 = "column2";

        work txn(conn);
        result res = txn.exec("SELECT " + tableName1 + "." + columnName1 + ", "
                              + tableName2 + "." + columnName2 +
                              " FROM " + tableName1 +
                              " JOIN " + tableName2 +
                              " ON " + tableName1 + ".id = " + tableName2 + ".id");
        txn.commit();

        cout << left << setw(20) << columnName1 << setw(20) << columnName2 << endl;
        cout << string(40, '-') << endl;

        for (const auto &row : res) {
            cout << left << setw(20) << row[0].c_str() << setw(20) << row[1].c_str() << endl;
        }
    } catch (const exception &e) {
        cerr << e.what() << endl;
        return 1;
    }

    return 0;
}
```
PostgreSQL 데이터베이스에 연결하고 JOIN 연산을 사용하여 여러 테이블에서 데이터를 검색한 다음 결과를 형식이 지정된 테이블로 출력하는 C++ 프로그램을 만들려면 libpqxx와 같은 라이브러리를 사용해야 합니다. 다음은 이를 수행하는 방법의 예입니다.

1. 먼저 시스템에 libpqxx 라이브러리를 설치합니다. 설치 방법은 https://github.com/jtv/libpqxx

2. 새 C++ 파일(예: main.cpp)을 생성하고 필요한 헤더를 포함합니다:

```cpp
#include <iostream>
#include <iomanip>
#include <pqxx/pqxx>

using namespace std;
using namespace pqxx;
```

3. 'main' 함수 내에서 PostgreSQL 데이터베이스에 대한 연결을 설정합니다:

```cpp
int main() {
    try {
        connection conn("dbname=your_database user=your_user password=your_password hostaddr=127.0.0.1 port=5432");
        if (conn.is_open()) {
            cout << "Connected to database successfully!" << endl;
        } else {
            cerr << "Cannot connect to database." << endl;
            return 1;
        }
```

your_database`, `your_user` 및 `your_password`를 PostgreSQL 설정에 적합한 값으로 바꿉니다.

4. 두 테이블 간에 JOIN 연산을 수행하는 SQL 쿼리를 실행합니다:

```cpp
        // Replace these table names and column names with your own
        string tableName1 = "table1";
        string tableName2 = "table2";
        string columnName1 = "column1";
        string columnName2 = "column2";

        work txn(conn);
        result res = txn.exec("SELECT " + tableName1 + "." + columnName1 + ", "
                              + tableName2 + "." + columnName2 +
                              " FROM " + tableName1 +
                              " JOIN " + tableName2 +
                              " ON " + tableName1 + ".id = " + tableName2 + ".id");
        txn.commit();
```

5. 결과를 형식이 지정된 표로 출력합니다:

```cpp
        cout << left << setw(20) << columnName1 << setw(20) << columnName2 << endl;
        cout << string(40, '-') << endl;

        for (const auto &row : res) {
            cout << left << setw(20) << row[0].c_str() << setw(20) << row[1].c_str() << endl;
        }
    } catch (const exception &e) {
        cerr << e.what() << endl;
        return 1;
    }

    return 0;
}
```

6. 프로그램을 컴파일하고 실행합니다:

```bash
g++ -std=c++11 main.cpp -lpqxx -lpq -o main
./main
```

이 예제에서는 조인에 사용할 수 있는 `id` 열이 있는 두 테이블이 있다고 가정합니다. 테이블 이름과 열 이름을 고유한 값으로 바꿉니다.

전체 코드는 다음과 같아야 합니다:

```cpp
#include <iostream>
#include <iomanip>
#include <pqxx/pqxx>

using namespace std;
using namespace pqxx;

int main() {
    try {
        connection conn("dbname=your_database user=your_user password=your_password hostaddr=127.0.0.1 port=5432");
        if (conn.is_open()) {
            cout << "Connected to database successfully!" << endl;
        } else {
            cerr << "Cannot connect to database." << endl;
            return 1;
        }

        // Replace these table names and column names with your own
        string tableName1 = "table1";
        string tableName2 = "table2";
        string columnName1 = "column1";
        string columnName2 = "column2";

        work txn(conn);
        result res = txn.exec("SELECT " + tableName1 + "." + columnName1 + ", "
                              + tableName2 + "." + columnName2 +
                              " FROM " + tableName1 +
                              " JOIN " + tableName2 +
                              " ON " + tableName1 + ".id = " + tableName2 + ".id");
        txn.commit();

        cout << left << setw(20) << columnName1 << setw(20) << columnName2 << endl;
        cout << string(40, '-') << endl;

        for (const auto &row : res) {
            cout << left << setw(20) << row[0].c_str() << setw(20) << row[1].c_str() << endl;
        }
    } catch (const exception &e) {
        cerr << e.what() << endl;
        return 1;
    }

    return 0;
}
```