[英]Converting vector<unsigned char> to const unsigned char*
[英]Converting Const char * to Unsigned long int - strtoul
我正在使用以下代碼將Const char *
轉換為Unsigned long int
,但輸出始終為0
。 我在哪里做錯了? 請告訴我。
這是我的代碼:
#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;
}
使用以10為基數:
nc=strtoul(n,&pEnd,10);
或允許自動檢測鹼基:
nc=strtoul(n,&pEnd,0);
strtoul
的第三個參數是要使用的基數,而您將其作為基數1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.