How to convert string to unsigned long in C++

2 Answers

0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;

int main()
{
	std::string s = "96540310";

	unsigned long ul = std::stoul(s);

	cout << ul << endl;

	return 0;
}

/*
run:

96540310

*/

 



answered May 24, 2018 by avibootz
0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;

int main()
{
	char s[] = "96540310";

	unsigned long ul = std::strtoul(s, NULL, 0);

	cout << ul << endl;

	return 0;
}

/*
run:

96540310

*/

 



answered May 24, 2018 by avibootz

Related questions

1 answer 62 views
1 answer 149 views
1 answer 52 views
1 answer 120 views
...