如题,我想查找字符串中某个字符,用find怎么做,在stl中。字符串如“姓名=张三”,我如何查找=

解决方案 »

  1.   

    std::string::find
    std::string::find_first_ofstring str("姓名=张三");
    string::size_type pos = str.find('=');
      

  2.   

    指针做法:char *str="姓名=张三";
    char *p=str;
    char *q;
    q=strstr(str,"=");
    int i=q-p;
      

  3.   

    恩,谢谢啦,我试了下,可以的,但是find返回的不是它的地址吗?怎么是一个整数,如3
      

  4.   

    如果是cstring类型的话可以直接这样
    str.Find("=")
      

  5.   

    Find函数的返回值是你要find的字符在字符串中的索引,也就是位置
      

  6.   

    看这个函数的说明
    http://www.cplusplus.com/reference/string/string/find_first_not_of/
      

  7.   

    VC下就用CString了,功能强大,看MSDN
    int Find( TCHAR ch ) const;
    int Find( LPCTSTR lpszSub ) const;
    int Find( TCHAR ch, int nStart ) const;
    int Find( LPCTSTR pstr, int nStart ) const;CString str = "姓名=张三";
    int iPos = str.Find("=");//iPos为4,Unicode 字符集下iPos为2
    if(iPos == -1)//未找到
    { }
    else
    { }
      

  8.   

    想查找字符串中某个字符,用find怎么做,按楼上的做。不过在stl中。字符串如“姓名=张三”,如何查找就不是这么回事了。vector <string> namevec;find(namevec.begin(),namevec.end(),"张三");或许你还得定义一个“函数对象”,网上查...