比如现在有个IP地址为192.168.1.1
分成4段提取存入字符串A、b、c、d中
谁知道如何存入

解决方案 »

  1.   

    int a,b,c,d;
    sscanf("192.168.0.1", "%d.%d.%d.%d", &a, &b, &c, &d);
      

  2.   

    #include <iostream>
    using namespace std;
    int _tmain(int argc, _TCHAR* argv[])
    {
    string str("192.168.1.1"); int i1 = str.find(".",0);
         cout << i1 << endl;
    string substring1 = str.substr(0,i1); cout << substring1 << endl;

    return 0;
    }
      

  3.   


    CString str = L"192.168.0.221";
    int index = 0;
    int i = 0;
    CString a, b, c, d; while(str.GetLength() != 0)
    {
    i = str.Find(L".");
    if (i < 0) break;
    switch(index)
    {
       case 0:
       {
        a = str.Left(i);
    break;
       }
       case 1: 
       {
         b = str.Left(i);
     break;
       }
     case 2: 
       { 
        c = str.Left(i);
    break;
       } }    
    str.Delete(0, i + 1);
    ++index;
    }    d = str;
      

  4.   


    CString str = L"192.168.0.221";
    int index = 0;
    int i = 0;
    CString a, b, c, d; while(str.GetLength() != 0)
    {
    i = str.Find(L".");
    if (i < 0) break;
    switch(index)
    {
       case 0:
       {
        a = str.Left(i);
    break;
       }
       case 1: 
       {
         b = str.Left(i);
     break;
       }
     case 2: 
       { 
        c = str.Left(i);
    break;
       } }    
    str.Delete(0, i + 1);
    ++index;
    }    d = str;