#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string cmd;
while(strcmp(cmd.c_str(),"exit")==0 && strcmp(cmd.c_str(),"\exit")==0)
{
cin>>cmd;
cout<<cmd;
}
return 0;
}
我被卡住了。如何比较字符串与const char *?
最好是直接将代码中的问题 – 2010-05-28 18:55:02
@布赖恩贴:我去这样做。 – sbi 2010-05-28 18:55:44
另外,如果使用cmd.compare(“exit”)而不是strcmp(cms,c_str(),“exit”),它会更干净== 0 您正在编写C++代码。为什么不利用它呢? – Vagrant 2010-05-28 19:04:33