Questions tagged [stoi]
18 questions
5
votes
1 answer
Why doesn't stoi allow std::basic_string as an input?
To increase the performance I'm trying to substitute std::string with custom specializations of std::basic_string where I'm replacing standard allocator with custom ones. One thing surprised me: the std::stoi class of functions requires constant…

Dmitry Kuzminov
- 6,180
- 6
- 18
- 40
3
votes
2 answers
Is there a more stringent version of std::stoi?
I just discovered (much to my surprise) that the following inputs do not cause std::stoi to throw an exception:
3.14
3.14helloworld
Violating the principle of least surprise - since none of these are valid format integer values.
Note, perhaps even…

FreelanceConsultant
- 13,167
- 27
- 115
- 225
1
vote
1 answer
Why stoi() function is not working in the following code?
class Solution {
public:
string kthLargestNumber(vector& nums, int k) {
priority_queueq;
for(int i=0;i

Palarax dope palarax
- 31
- 3
1
vote
1 answer
How would I go about converting a string to int?
I'm watching a Youtube guide about "if statements" and wanted to experiment a little but by adding a third outcome that the numbers are equal but I keep getting thrown this error:
No suitable conversion function from "std::string to "int"…

otis
- 39
- 2
1
vote
1 answer
Why doesn't g++ recognize stoi even using C++11?
I have this function in C++11:
bool ccc(const string cc) {
vector digits;
int aux;
for(int n = 0; n < cc.length(); ++n) {
digits.push_back(to_string(cc[n])); }
for(int s = 1; s < digits.size(); s += 2) {
aux =…

MxtApps
- 21
- 4
1
vote
3 answers
"stoi" was not declared in this scope
I have fixed it another way but I still want to know why stoi is not working here. This is the code:
#include
#include
std::string fakeBin(std::string str){
for(int i=0;i

Raihan_Alam
- 89
- 2
- 10
1
vote
0 answers
Terminating with uncaught exception of type std::invalid_argument: stoi: no conversion
Can't understand where this error is coming from. Trying to follow an example tutorial and my version isn't working. What's the deal?
libc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no…

blood runner
- 63
- 9
0
votes
0 answers
speech metric code argument of type 'NoneType' is not iterable
I am trying to using the code from github to calculate stoi, cbak, ssnr, csig and covl (source from: https://github.com/santi-pdp/segan_pytorch/blob/master/eval_noisy_performance.py)
BUt I got an error says argument of type 'NoneType' is not…

aozora-hime
- 1
- 2
0
votes
1 answer
convert str[i] into integer type using stoi()
I have a string of number and I want to convert each number into integer type then add it into a vector.
#include
#include
#include
using namespace std;
int main() {
vector vec;
…

soappy
- 3
- 1
0
votes
0 answers
Why does my array change its values from the correct ones to random ones when it exits the while loop?
I am trying to take a string of numbers and commas, then separate the numbers from the commas and turn them into ints and store them into an array. I print out the array in the while loop, and it works perfectly fine, but when I try printing the…

usherא
- 1
- 1
0
votes
1 answer
Error when trying read pixel data from PGM file
I am trying implement a c++ class to read a PGM file. I can read the header of file (magic number, width, height and max_value) without problem, but when I try read the pixel data, I got an error related to the conversion of the string with…

Kleber Mota
- 8,521
- 31
- 94
- 188
0
votes
1 answer
terminate called after throwing an instance of 'std::out_of_range' c++
my assignment is to do the following:
Generate some rows of numeric digits.
Use the random number generator.
Ask the user for the number of rows and columns of digits.
2x4 would look like this...
0655
6476
Treat each row of digits as a single…
0
votes
1 answer
How I compare the two strings of digits of size >=100 ? Because on using stoi and stoll giving me overflow RUNTIME ERROR
How I compare the two strings of digits of size 100 ? Because on using stoi and stoll giving me overflow RUNTIME ERROR
terminate called after throwing an instance of 'std::out_of_range'
what(): …

Ankit Pathak
- 13
- 5
0
votes
2 answers
i am trying to use getline to read a csv file line by line and separate the data in the file and turn a string into int
I am a beginner and I just need a bit of help on why I getline is showing an error:
this is what I have so far
#include
#include
#include
#include
using namespace std;
const double TAX_RATE = 0.0825;
const…
user18453148
0
votes
2 answers
stoi() terminate after throwing and instance of 'std::invalid argument in c++-- What am I doing wrong?
Fairly new to coding. Trying some of the easy projects at LeetCode, and failing... Ha! I am trying to take an integer and convert it to a string so I can reverse it, then re-convert the reversed string back into a integer.
This code is throwing the…

jeremyers1
- 3
- 3