stringstream版
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
template<typename out_type, typename in_value>
out_type convert(const in_value & t)
{
stringstream stream;
stream<<t;//向流中传值
out_type result;//这里存储转换结果
stream>>result;//向result中写入值
return result;
}
int main()
{
string str="10.20.10.10";
int pos=0;
int posend;
//stringstream ss;
string tmp;
int n;
int res=0;
int i=0;
while((posend=str.find('.',pos))!=string::npos)
{
tmp=str.substr(pos,posend-pos);
//ss.clear();
//ss<< tmp;
//ss>> n;
n=convert<int>(tmp);
n <<= i;