C++高手帮忙修改一下关于字符串的程序

来源:百度知道 编辑:UC知道 时间:2024/05/27 20:56:23
通过以下程序想实现,从某一字符串指针中查找ID并存储找到的ID数值,帮忙改改。

#include "stdafx.h"

#include <iostream>
#include <string>
#include <comdef.h>
#include <stdio.h>
using namespace std;

void GetUserPosInfo(char * pStr, int & UserID);

int main(int argc, char* argv[])
{
char *p="ID=123412342";

int xUserID;
GetUserPosInfo(p, xUserID);
cout<<"ID="<<xUserID<<endl;

}

void GetUserPosInfo(char * pStr, int & UserID)
{
std::string strValue(pStr);

int iNumber = 0 ;

string::size_type ipos=strValue.find("ID=");

//iTemp = iPos;
//for(i=;i<strlen(pStr);i++)
while(*(pStr+ipos))
{
if ((*(pStr+ipos)<=57)&&(*(pStr+ipos)>=48))
{

//*(pStr+ipos) = '\0' ;

//co

#include <iostream>
#include <string>
using namespace std;

int GetUserPosInfo(char * pStr);

int main()
{
char *p = "ID=123412342";
int xUserID = GetUserPosInfo( p );
cout<<"ID="<<xUserID<<endl;
return 0;
}

int GetUserPosInfo(char * pStr)
{
string strValue(pStr);

string::size_type bpos = strValue.find("ID=") + 3;
string::size_type fpos = bpos;
for( ; fpos<strValue.length() && strValue[fpos] >= '0' && strValue[fpos] <= '9'; fpos++ );

string ID( strValue, bpos, fpos );
return atoi(ID.c_str());
}

如果你要用C ,我倒可以给你.C++不懂.