Cygwin gcc c++ c99 库错误 stod 无法识别使用的 strtod

Cygwin gcc c++ c99 libraries error stod not recognized used strtod instead

本文关键字:识别 strtod stod c++ gcc c99 错误 Cygwin      更新时间:2023-10-16

这个问题是继:C ++将文本文件中的C++读取到Vector然后根据内部向量中的第一个单词写入Vector或数组.我编辑这个问题是因为第一个问题只是一个错别字错误(无法问单独的 Q,因为我之前尝试过并投票支持重复??,也无法删除 Q,因为有答案..),更重要的问题是关于 cygwin c++ 编译器无法访问 c99 库。当使用 stod 而不是 strtod 时,我得到一个编译错误。问题是_GLIB_CXX_USE_C99未定义??

到目前为止的代码:

#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
#include <cstdlib>
#if __cplusplus < 201103L
#warning No C++11 support
#endif
#if !defined(_GLIBCXX_USE_C99)
#warning No C99 library functions
#endif
#if defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
#warning Broken vswprintf
#endif
std::vector<double> GetValues(const std::vector<std::string>& src, int start, int end, std::string typeline)
{
    std::vector<double> ret;
    for(int i = start; i <= end; ++i)
    {
      if(typeline == "E3T" && i == 5)
    {
      ret.push_back(std::strtod(src[2].c_str(), nullptr));
      ret.push_back(std::strtod(src[i].c_str(), nullptr));
    }
      else
    {
          ret.push_back(std::strtod(src[i].c_str(), nullptr));
    }
    }
    return ret;
}
void PrintValues(const std::string& title, std::vector<std::vector<double>>& v)
{
    std::cout << title << std::endl;
    for(size_t line = 0; line < v.size(); ++line)
    {
        for(size_t val = 0; val < v[line].size(); ++val)
        {
            std::cout << v[line][val] << " ";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}
int main()
{
    std::vector<std::vector<std::string>> values;
    std::ifstream fin("example.2dm");
    for (std::string line; std::getline(fin, line); )
    {
        std::istringstream in(line);
        values.push_back(
            std::vector<std::string>(std::istream_iterator<std::string>(in),
            std::istream_iterator<std::string>()));
    }
    std::vector<std::vector<double>> cells;
    std::vector<std::vector<double>> nodes;
    for (size_t i = 0; i < values.size(); ++i) 
    {
        if(values[i][0] == "E3T")
        {
      cells.push_back(GetValues(values[i], 1, 5, "E3T"));
        }
        else if(values[i][0] == "E4Q")
        {
      cells.push_back(GetValues(values[i], 1, 6, "E4Q"));
        }
        else if(values[i][0] == "ND")
        {
      nodes.push_back(GetValues(values[i], 1, 4, "ND"));
        }
    }
    PrintValues("Cells", cells);
    PrintValues("Nodes", nodes);
    return 0;
}

编译警告(cygwin gcc c++):

$ g++ read_csv3.cpp -std=c++11
read_csv3.cpp:15:2: warning: #warning No C99 library functions [-Wcpp]

有人知道如何在 cygwin 中解决这个问题吗?

你可能想要这个:

 if(typeline == "E3T" && i == 5)
                            ^^ equality check

if(typeline == "E3T" && i = 5)抱怨左值

因为typeline == "E3T" && i不能被分配为 5

然而

if(typeline == "E3T" && (i = 5))编译,但这不是你需要的