gpt4 book ai didi

c++ - 比较两个 char* 是否相等

转载 作者:可可西里 更新时间:2023-11-01 15:38:16 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is the proper function for comparing two C-style strings?

我的匹配条件不起作用!有人可以建议如何与 C 风格的字符串进行比较吗?

void saveData(string line, char* data){
char *testString = new char[800];
char *stpr;
int i=0;
bool isData=false;
char *com = data;
strcpy(testString,line.c_str());
stpr = strtok(testString, ",");
while (stpr != NULL) {
string temp = stpr;
cout << temp << " ===== " << data << endl;

即使 tempdata 匹配,以下条件也不起作用:

if (stpr==data) {
isData = true;
}

不确定这是否有帮助。 SaveData() 函数从以下函数调用:

void readFile(char* str){
string c="", line, fileName="result.txt", data(str);
ifstream inFile;
inFile.open(fileName.c_str());
resultlist.clear();

if(inFile.good()){
while(!inFile.eof()){
getline(inFile, line);
if(line.find(data)!=string::npos){
cout << line << endl;
}
saveData(line, str);
}
inFile.close();
}

}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com