可能重复:
What is the proper function for comparing two C-style strings?比较两个char *平等
我的比赛状态不行!有人可以建议如何比较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;
即使temp
和data
比赛,以下情况不工作:
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();
}
}
什么是你想怎么办? – elyashiv
对不起,这是我的错。这是比较2个字符* –