【发布时间】:2011-09-28 06:09:00
【问题描述】:
我有一个字符串"8120, 8120NGE, 8120NG, 8130, 8130NG, 8130NGE"。
我有一个char* (0x0012d094 "8130")
我想看看“8130”是否在里面。那个确切的词。
所以我正在使用
istringstream iss(boards);
string token;
AVBOOL foundBool=FALSE;
while(std::getline(iss, token, ','))
{
const char * compareToken = token.c_str();
token.compare(board); // with that : it doesn't work cause "8130" is not equal 0x0012d094 "8130"
if(strcmp(compareToken,board)==0) //with that it doesnt work cause 0x0012cef0 " 8130" is not equal 0x0012d094 "8130"
{
foundBool=TRUE;
}
}
所以问题是我如何将字符串与 char * 进行比较。
我是否需要将 char 转换为字符串然后使用 string.compare 要么 我需要将字符串转换为char并使用strcmp吗? 要么 我需要做点别的吗?
我有点迷路了。
【问题讨论】: