首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么判断输入字符为已知字符

2012-03-11 
如何判断输入字符为已知字符不知道大家明白我标题的意思没?我自己也不知道要怎么表达啊....#includeiostr

如何判断输入字符为已知字符
不知道大家明白我标题的意思没?
我自己也不知道要怎么表达啊....
#include       <iostream>  
using   namespace   std;    
    int         main()      
    {      
            char       str[20];      
            cout < < "Input       : ";      
            cin.get(str,19);      
            cout < <str < <endl;      
            system( "PAUSE ")
    }      
比如上面的那个程序,可以输入一个字符串的
假如我输入 "win "那么我该如何判断我输入的就是 "win "呢?
我一开始是想这样子的:
#include       <iostream>  
using   namespace   std;    
    int         main()      
    {      
            char       str[20];      
            cout < < "Input       : ";      
          if((cin.get(str,19)== 'win '));
            system( "PAUSE ");
    }      
但是提示这样子是不行的
那么我该如何判断呢?

[解决办法]
#include <iostream>
using namespace std;
int main()
{
char str[20];
cout < < "Input : ";
cin.get(str,19);
if (strcmp(str, "win ") == 0) // 用strcmp判断
cout < <str < <endl;
system( "PAUSE ");
return 0;
}
[解决办法]
char str[20];
cout < < "Input : ";
cin.get(str,19);
cout < <str < <endl;
==》
string str;
cout < < "Input : ";
getline(cin, str);
if(str== "win ") cout < <str < <endl; //string operater=

热点排行