This question follows on from : c++ reading in text file into vector<vector> then writing to vector or array depending on first word in internal vector . Im editing this question because the first issue was simply a typo error (couldn't ask a separate Q because Ive tried that before and got down voted for duplicate??, also couldnt delete Q because has answers..), and the more important question is about the cygwin c++ compiler not having access to c99 libraries. When using stod instead of strtod i get an compilation error. The issue is _GLIB_CXX_USE_C99 is undefined??
Code so far:
#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;
}
Compilation warning (cygwin gcc c++):
$ g++ read_csv3.cpp -std=c++11
read_csv3.cpp:15:2: warning: #warning No C99 library functions [-Wcpp]
Anyone know how to fix this in cygwin?