I have gcc (Cadence) 4.8.3. And I want to compile a c++ file which has an include string_view. When I compile the file:
g++ script.cpp
the following error occurs:
script.cpp:4:23: fatal error: string_view: No such file or directory
#include <string_view>
^
compilation terminated.
I tried upgrading my gcc version but I couldn't.
sudo apt-get install gcc-5
sudo: apt-get: command not found
My question is how can I fix this problem, how can I upgrade my gcc version or is there an alternative that can replace the string_view library.
The .cpp script is the following:
#include <iostream>
#include <string>
#include <map>
#include <string_view>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include<cmath>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>
#define FEATURE 27
double get_value(std::string_view value_str,double* smons) {
std::map<std::string, double *> arrays_names {
{"smons", smons}
};
auto name_end_pos = value_str.find('[');
auto name = value_str.substr(0, name_end_pos);
auto index_end_pos = value_str.find(']');
auto index_len = index_end_pos - name_end_pos - 1;
std::string index_str{value_str.substr(name_end_pos + 1, index_len)};
auto index = std::stoi(index_str);
return arrays_names[std::string(name)][index];
}
double evaluate_expression(const std::string& expr,double* smons) {
double a;
if (expr.size()==8)
{
a=get_value(expr.substr(0, 8),smons);
}
else if (expr.size()==9)
{
a=get_value(expr.substr(0, 9),smons);
}
else if (expr.size()==17)
{
a=get_value(expr.substr(0, 8),smons) * get_value(expr.substr(9, 8),smons);
}
else if (expr.size()==18)
{
a=get_value(expr.substr(0, 8),smons) * get_value(expr.substr(9, 9),smons);
}
else if (expr.size()==19)
{
a=get_value(expr.substr(0, 9),smons) * get_value(expr.substr(10, 9),smons);
}
return
a;
}