0

I have some code, it's quite large so I'll just create a snapshot of it here:

int l = 3;
vector<int> weights;   

void changeWeights(int out){
    for (int i = 0; i < weights.size(); i++){
        int w = std::stoi(std::to_string(weights[i])) -
        out*std::stoi(std::to_string(weights[i]));
        if (w < -l){
          w = -l;
        } else if(w > l){
            w = l;
        }
        weights.assign(i, w);
    }
}

I get errors on both the 'stoi' and 'to_string' function calls in the form of

Main.cpp:35:21: error: ‘stoi’ is not a member of ‘std’
         int w = std::stoi(std::to_string(weights[i])) -
                 ^
Main.cpp:35:31: error: ‘to_string’ is not a member of ‘std’
         int w = std::stoi(std::to_string(weights[i])) -
                           ^
Main.cpp:36:17: error: ‘stoi’ is not a member of ‘std’
         out*std::stoi(std::to_string(weights[i]));
             ^
Main.cpp:36:27: error: ‘to_string’ is not a member of ‘std’
         out*std::stoi(std::to_string(weights[i]));

I have read some similar queries whereby the answer was to add in -std=c++11 or -std=c++0x when compiling - both these solutions did not work. Another solution suggested a bug in the compiler version but it's not the compiler I am using I do not think. I am using g++ (GCC) 5.0.0 20141005 (experimental) version on a 64x Apple Macbook Pro.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
coffm
  • 21
  • 1
  • 4

1 Answers1

4

Usage of stoi() and to_string() in this part of code is pretty weird, and completely unnecessary. You can simply write

int w = weights[i] - out * weights[i];

To use std::stoi() and std::to_string() you need to have a proper

#include <string>

statement, and the c++11 language options set (see the links to the documentation reference above).

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190