[問題] 有關strtok

看板C_and_CPP (C/C++)作者時間16年前 (2009/07/13 15:43), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/1
請問下面的程式 #include <iostream> #include <string> using namespace std; int main(int argc, char *argv[]) { char *sub_ptr; char test[]="L=3"; sub_ptr=strtok(test,"="); cout << "sub_ptr=" << sub_ptr << endl; if(sub_ptr=="L") cout << "sub_ptr=L" << endl; else cout << "sub_ptr!=L" << endl; system("PAUSE"); return EXIT_SUCCESS; } sub_ptr就是L,但為什麼跳不進if(sub_ptr=="L")的判斷中 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.114.102

07/13 15:44, , 1F
用strcmp()
07/13 15:44, 1F

07/13 15:45, , 2F
請愛用strcmp() :)
07/13 15:45, 2F

07/13 15:52, , 3F
多謝兩位
07/13 15:52, 3F
文章代碼(AID): #1AMkMD_J (C_and_CPP)
文章代碼(AID): #1AMkMD_J (C_and_CPP)