Answers for "parse a string to number C++"

C++
1

convert string to number c++

#include <iostream>
#include <sstream>
using namespace std;
int main()
{
	string str = "123456";
 	int n;
  	stringstream ( str ) >> n;
	cout << n; //Output:123456
	return 0;
}
Posted by: Guest on April-16-2021
0

convert string to number c++

//stoi() : The stoi() function takes a string as an argument and 
//returns its value. Supports C++11 or above. 
// If number > 10^9 , use stoll().
#include <iostream>
#include <string>
using namespace std;
main() {
	string str = "12345678";
	cout << stoi(str);
}
Posted by: Guest on April-16-2021

Browse Popular Code Answers by Language