我正在使用以下代码将Const char *
转换为Unsigned long int
,但输出始终为0
。我在哪里做错了?请告诉我。将Const char *转换为Unsigned long int - strtoul
这里是我的代码:
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;
int main()
{
vector<string> tok;
tok.push_back("2");
const char *n = tok[0].c_str();
unsigned long int nc;
char *pEnd;
nc=strtoul(n,&pEnd,1);
//cout<<n<<endl;
cout<<nc<<endl; // it must output 2 !?
return 0;
}
顺便说一句,如果有人想将其转换为一个'无符号长long',功能['标准:: stoull'(HTTP: //www.cplusplus。com/reference/string/stoull /),而'unsigned long'是['std :: stoul'](http://www.cplusplus.com/reference/string/stoul/)。 – Volomike