我是用标准C++的gets从键盘输入得到一个字符串,现在我想把这个大的字符串以空格为分隔符解析为几个小的字符串,我应该怎么做,大家帮帮忙啊,急

解决方案 »

  1.   

    if you are using MFC, look into
    String Tokenizer Class (CTokenEx) 
    http://www.codeguru.com/cpp_mfc/CTokenEx.shtmlif you are using STL, look into
    A string tokenizer 
    http://www.tldp.org/HOWTO/C++Programming-HOWTO-7.html
      

  2.   

    for(i=0; i<strlen(str); i++)
    {
         strcat(temp ,str);//追加字符串至temp
          if(*str == ' ')
          {
             //保存temp
             //清空temp
          }
          else
          {
           str++;
           }
    }你在完善一下看看,基本上如此
      

  3.   

    比如:buf是要解析的字符串,first、second为解析后的两个子串:istrstream strcin( buf );
    strcin >> first >> second;即可。for example:/* main.cpp */#include <iostream.h>
    #include <strstrea.h>
    #include <string.h>int main()
    {
    char buf[256];
    char show[20][30]; memset(show,0,20*30);

    cin.getline(buf, 256); istrstream strcin( buf ); int i = 0;
        
    do
    {
    strcin >> &show[i][0];
    i++; }while(i <20 && (&show[i][0] != ""));
    i = 0;
    while(show[i][0] != 0)
    {
    cout <<&show[i][0] <<endl;
    i++;
    }
    return 0;
    }