[英]how to convert ascii to unsigned int
有沒有將字符串轉換為unsigned int的方法? _ultoa存在但無法找到vise版本...
std::strtoul()
是其中之一。 然后又有像atoi()
這樣的舊版本。
Boost提供lexical_cast。
#include <boost/lexical_cast.hpp>
[...]
unsigned int x = boost::lexical_cast<unsigned int>(strVal);
或者,你可以使用stringstream(這基本上是lexical_cast在幕后的內容):
#include <sstream>
[...]
std::stringstream s(strVal);
unsigned int x;
s >> x;
sscanf會做你想要的。
char* myString = "123"; // Declare a string (c-style)
unsigned int myNumber; // a number, where the answer will go.
sscanf(myString, "%u", &myNumber); // Parse the String into the Number
printf("The number I got was %u\n", myNumber); // Show the number, hopefully 123
如果你通過_atoi64去了它
unsigned long l = _atoi64(str);
int atoi (const char * str)怎么樣?
string s("123");
unsigned u = (unsigned)atoi(s.c_str());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.