可能重複:「是的,它的工作原理」
How do I properly compare strings in C?簡單,如果用繩子
#include <iostream>
using namespace std;
int main(){
char name[100];
cout<<"Enter: ";
cin>>name;
if(name == "hello"){
cout<<"Yes it works!";
}
return 0;
}
爲什麼當我在我沒有拿到提示符下輸入打招呼信息?
因爲'name'不是一個字符串,它是一個字符數組。 – 2012-04-29 14:41:51
使用'std :: string'!該代碼易受緩衝區溢出的影響。如果你真的在使用C++,那麼你就開始使用STL類。 – mfontanini 2012-04-29 14:49:13