请教怎样把char* a = new char([100] 转成 int型?
请教怎样把char* a = new char([100] 转成 int型?
比如 a的第10到第12的位置,是 123,希望将123转称 int型值
谢谢
[解决办法]
char temp[3] = {0};
memcpy(temp, a+9, 3);
int b = atoi(temp);
#include <iostream>
#include <iterator>
#include <regex>
#include <string>
int main()
{
std::string const strs("This is a book 123, a pen 321, a human 345");
std::regex reg("\\d+");
std::vector<int> nums;
for(std::sregex_iterator begin(std::begin(strs), std::end(strs), reg), end; begin != end; ++begin){
nums.emplace_back(std::stoi(begin->str()));
std::cout<<nums.back()<<std::endl;
}
return 0;
}