C++解析字符串中数据


#include <iostream>
#include <string.h>
#include<sstream>
 
 
using namespace std;
 
 
int main()
{
    double val;
    char line[] = "-1000.9kasjdfksa";
    int after;
    char *start;
    start = line;
    after = strspn(start,"-+");
    printf("dddd %d\n",after);
    cout<<"after-->"<<after<<endl;
 
 
    after = strspn(start+after, "0123456789.") + after;
 
 
    std::string st(start, start+after);
    std::stringstream s(st);
 
 
    cout<<"after--->"<<after<<endl;
    if(!(s >> val)) printf(" this is bad value \n");
    cout << "Hello World!"<<val << endl;
    return 0;
}
 

你可能感兴趣的:(C++解析字符串中数据)