这有什么不对? [英] What's wrong in this?

查看:95
本文介绍了这有什么不对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream.h>
#include<stdio.h>
#include<string.h>
void main()
{
char a[20];
cout<<"Please enter the required password"<<endl;
cin>>a;
if (a=="strike"){
cout<<"access Granted!"<<endl;
} 
gets(a);
}

推荐答案



你已经知道了字符串头文件所以不要使用直接使用char指针,最好使用这样的字符串:




you already know about string header file so instead of using char pointers directly, its better to use the strings like this :

#include<iostream>

int main()
{
std::string userInput;
std::cout<<"Please enter the required password"<<std::endl;
std::getline(std::cin,userInput);

std::string actualPassword = "strike";

if(userInput == actualPassword)
std::cout<<"access Granted!"<<std::endl;

return 0;
}





仍然可以自己找出char数组与std :: string的不同之处.Google是你的朋友。

并且如评论中已经提到的那样,尝试更好地理解这些概念。



希望这有助于!!



still find out on your own how char array is different from std::string.Google is your friend.
and as already mentioned in comments, try to better your understanding of the concepts.

hope this helps !!


这篇关于这有什么不对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆