#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string secret = "abracadabra";
    string password;
    cout << "Enter password:" << endl;
    getline(cin,password);
    if(secret == password)
        cout << "Access granted" << endl;
    else
        cout << "Sorry";
    return 0;
}


我尝试运行上述程序,但是在输入abracadabra并按Enter键后,程序将继续运行,

我发现有问题,这次我使用了一个不同的想法eclipse,它可以正常工作。

为什么上面的程序不能在eclipse中工作,而在netbeans中工作?

最佳答案

在开始运行程序之前,两个IDE都必须连接cin和cout的文件流。显然,netbeans的做法不同于eclipse。

要查看自然行为,请编译程序并从命令提示符处启动它。

我没有足够的声誉来添加评论,但是@AMDG的答案假设您密码中不能包含空格或制表符。

09-04 07:07
查看更多