小编Dan*_*iel的帖子

编译包含exprTk的c ++文件时遇到麻烦

我有一些麻烦编译包括exprtk在内的c ++代码.我想编译一个给定的包示例(我称之为parser.cpp):

#include <cstdio>
#include <string>
#include "exprtk.hpp"


template <typename T>
void trig_function()
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>     expression_t;
   typedef exprtk::parser<T>             parser_t;

   std::string expression_string = "clamp(-1.0,sin(2 * pi * x) + cos(x / 2 * pi),+1.0)";

   T x;

   symbol_table_t symbol_table;
   symbol_table.add_variable("x",x);
   symbol_table.add_constants();

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;
   parser.compile(expression_string,expression);

   for (x = T(-5); x <= T(+5); x += T(0.001))
   {
      T y = expression.value();
      printf("%19.15f\t%19.15f\n",x,y);
   }
}

int main()
{
    trig_function<double>();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

因此我在cmd中使用以下命令:

g++ -c -o …
Run Code Online (Sandbox Code Playgroud)

c++ g++ string-parsing exprtk

8
推荐指数
1
解决办法
665
查看次数

标签 统计

c++ ×1

exprtk ×1

g++ ×1

string-parsing ×1