I'm currently trying to convert a string into three integers. I need to do some math with "11", "5" and "2". At least in this example. I tryed to convert the string using stoi() into integers, but I couldn't do the part where I take only a part of the string, like in my second example down below. Is there a simple solution for this? I started programming in C++ this week, so I don't have much knowledge.
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;
int main() {
int seconds 01 = 0;
int seconds 10 = 0; // somehow either one was beeing set to 35 by default, so I had to do
this
int minutes = 0;
string time = "11:52"; // mm:ss format
// I need to convert the string into three integers
cout << minutes << " " << seconds10 " " << seconds01;
return 0;
}
Second example:
string time = "01:50"; // mm:ss format
int seconds10 = stoi(time[3]);
// [Error] call of overloaded 'stoi(char&)' is ambiguous
Function:
minutes should output "11"
seconds10 = 5
seconds01 = 2