stangreg / Ignitron

An ESP32 based foot pedal to control the Spark Amp and connect to the App using Bluetooth LE.
BSD 3-Clause "New" or "Revised" License
35 stars 11 forks source link

Compilation error: 'stoi' was not declared in this scope #20

Closed MrBarnickle closed 12 months ago

MrBarnickle commented 12 months ago

Hello, I have a problem when I try to compile the program. The error I get is: Compilation error: 'stoi' was not declared in this scope

C:\Arduino\Ignitron\src\SparkDataControl.cpp: In member function 'int SparkDataControl::init(int)': C:\Arduino\Ignitron\src\SparkDataControl.cpp:67:29: error: 'stoi' was not declared in this scope sparkModeInput = stoi(line); ^ C:\Arduino\Ignitron\src\SparkDataControl.cpp:97:30: error: 'stoi' was not declared in this scope currentBTMode_ = stoi(line);

Arduino IDE Version 2.1.1 WEMOS LOLIN32

Can someone help me?

Thanks!!

stangreg commented 12 months ago

@MrBarnickle you have to make sure to use C++11 when compiling. Please see here: https://stackoverflow.com/questions/22084783/function-stoi-not-declared

MrBarnickle commented 12 months ago

@stangreg: from my platform.txt compiler.cpp.flags=-std=gnu++11 -Os -g3 -Wpointer-arith -fexc.... Output from __cplusplus: 201103

stangreg commented 12 months ago

@MrBarnickle you can try if the suggested fix to change from stoi call to atoi call as suggested further down that site. I can only check myself next week as I don't have access to my environment at the moment. If you try, let me know if it works.

MrBarnickle commented 12 months ago

@stangreg: Thanks!!! atoi solved this problem.

ServError commented 12 months ago

Just thought I'd throw in a side note/alternative that's not C++11 dependent. Since sparkModeInput only uses a single character and currently won't exceed a value of '9', you can replace the stoi calls for it with

(int)(line[0]-'0')

This leaves a potential hole down the road, but it is functional in the code's current state.