检查字符

Checking characters

本文关键字:字符 检查      更新时间:2023-10-16

如何检查字符数组?例如,我正在编写一个程序,要求我输入密码,比如ZEZO,然后它检查密码是否正确,然后打印"hello ZEZO"。我目前使用turbo c++为学校的东西。我有一个示例程序:

#include <iostream.h>
#include <conio.h>
void main()
{
    clrscr();
    char * zezo;
    zezo = "Zezo";
    cout<<"Hello "<<zezo;
}

我只需要知道如何得到单词检查

使用std::string代替char*,然后使用operator ==compare检查字符串

iostream.hconio.h ?void main吗?寻找新的学习材料,越快越好,因为不管你现在学的是什么,都是非常糟糕的。

#include <iostream>
#include <string>
int main() {
    std::string s;
    std::cin >> s;
    if (s == "Zezo")
        // Cool
    else
        // Not cool 
}

strcmp

bool matches = strcmp(zezo, "ZEZO") == 0

查找strcmp,最好查找std::string和相关函数