0

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

#include <iostream.h>
#include <conio.h>

void main()
{
    clrscr();
    char * zezo;
    zezo = "Zezo";

    cout<<"Hello "<<zezo;
}

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

4

4 回答 4

5

使用 astd::string代替 a char*,然后使用其中一个operator ==compare来检查字符串。

于 2013-01-15T12:07:29.773 回答
3

iostream.hconio.hvoid main? 尽快找到新的学习材料,因为无论你从中学习什么,都非常糟糕。

#include <iostream>
#include <string>

int main() {
    std::string s;
    std::cin >> s;
    if (s == "Zezo")
        // Cool
    else
        // Not cool 
}
于 2013-01-15T12:10:08.290 回答
0

strcmp

bool matches = strcmp(zezo, "ZEZO") == 0
于 2013-01-15T12:07:18.077 回答
0

搜索 strcmp 和更好的 std::string 和相关函数

于 2013-01-15T12:09:41.167 回答