strtokの後に文字列を比較しようとしていますが、trueではなくfalseになっているようです
strtokを使用している場合、他に何かする必要がありますか?
char file[] = "temp.txt";
ifstream getfile;
getfile.open(file,ios::in);
if(getfile.is_open())
{
char data[256];
char *line;
const char * test = "init";
//loop till end of file
while(!getfile.eof())
{
//get data and store to variable data
getfile.getline(data,256,'\n');
line = strtok(data," ");
while(line != NULL)
{
cout << "Comparing " << line << " with " << test <<endl;
//This is suppose to print but it dosent
if(line == test)
cout << line << endl;
line = strtok(NULL," ");
}
}
}
出力:
comparing init with init
必要な出力:
comparing init with init
init
ありがとう!:D
===========================
以下に変更して動作しました!:)
if(strcmp(line,test)==0)