what is wrong with stoi

#include<bits/stdc++.h>
#include<string.h>
#include<stdlib.h>
using namespace std;

int main()
{
string str1=“10”;
int i=0;
while(str1[i]!=’!’)
{
i++;
}
// string str2=str1.substr(i+1,str1.length());
// cout<<str2;
int k;
k= stoi( str1 );
cout<<k;
return 0;
}

You have to run while loop till ‘\0’ character or simply NULL as last character in a string is NULL. Just correct that.

Using stoi()

int main() { 
	
	string str1="10"; 
	int i=0; 
	while ( str1[i]!='\0' ) 
	{ 
		i++; 
	} 
	// string str2=str1.substr(i+1,str1.length()); 
	// 	cout << str2; 
	int k; 
	k = stoi(str1); 
	cout << k; 
	return 0; 
}

Here is the link to your updated code.

thankssssssss!