簡體   English   中英

帶有 libpqxx-header 的 C++ 產生錯誤 C2039:“encoding_group”:不是“全局命名空間”的成員

[英]C++ with libpqxx-header produces error C2039: 'encoding_group': is not a member of '`global namespace''

我做 PostGreSQL 查詢已經 6 個月了,想用libpqxx做一些工作,我使用 DB 中的數據通過libpqxx訪問(通過 vcpkg 獲得的vcpkg )。

我的環境是 Visual Studio 2019。 Properties-> C/C++ -> Language: ISO C++17 Standard (/std:c++17)

在嘗試編譯我找到的示例時,當包含來自 include/pqxx/pqxx 的 array.hxx 時,出現以下錯誤:

------ Build started: Project: pqxx-test2, Configuration: Debug Win32 ------
1>pqxx-test2.cpp
1>C:\Users\olebe\OneDrive\Documents\Projects\vcpkg\packages\libpqxx_x86-windows\include\pqxx\array.hxx(66,62): error C2039: 'encoding_group': is not a member of '`global namespace''
1>Done building project "pqxx-test2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

這是我嘗試編譯的代碼:

#include <iostream>
#include <pqxx/pqxx>

/// Query employees from database.  Return result.
pqxx::result query()
{
    pqxx::connection c{ "postgresql://accounting@localhost/company" };
    pqxx::work txn{ c };

pqxx::result r = txn.exec("SELECT name, salary FROM Employee");
for (auto row : r)
std::cout
// Address column by name.  Use c_str() to get C-style string.
<< row["name"].c_str()
<< " makes "
// Address column by zero-based index.  Use as<int>() to parse as int.
<< row[1].as<int>()
<< "."
<< std::endl;

// Not really needed, since we made no changes, but good habit to be
// explicit about when the transaction is done.
txn.commit();

// Connection object goes out of scope here.  It closes automatically.
return r;
}


/// Query employees from database, print results.
int main(int, char* argv[])
{
  try
  {
    pqxx::result r = query();

    // Results can be accessed and iterated again.  Even after the connection
    // has been closed.
    for (auto row : r)
    {
      std::cout << "Row: ";
      // Iterate over fields in a row.
      for (auto field : row) std::cout << field.c_str() << " ";
      std::cout << std::endl;
    }
  }
  catch (const pqxx::sql_error & e)
  {
    std::cerr << "SQL error: " << e.what() << std::endl;
    std::cerr << "Query was: " << e.query() << std::endl;
    return 2;
  }
  catch (const std::exception & e)
  {
    std::cerr << "Error: " << e.what() << std::endl;
    return 1;
  }
}

有沒有人遇到過這個??

錯誤信息“'encoding_group': is not a member of '`global namespace”表示編譯器在全局命名空間中找不到變量 encoding_group 的聲明。 所以我的建議是找到這個encoding_group的聲明,看看這個變量到底是在哪里聲明的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM