为什么在for循环中,布尔值变为true

时间:2018-03-24 17:35:35

标签: gcc c++14 boolean-operations

你好我是c ​​++的新手,我有一个代码的问题,有人可以解释为什么fra的布尔值没有在for循环内发生变化。

是代码的一部分,还是c ++ 14中bool的属性。代码是使用gnu gcc编译器编译的。 我的代码如下。

    #include <cstdio>
    using namespace std;
    bool frag= false;

    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        char input[1000];
        cin>>input;
        int n;
        n=strlen(input);

        int val[5] ={1,2,3,4,5};
        for (int i = 0; i < n; i++) {
            //cout<<input[i]<<endl;
            int k=input[i];
            if(k==1 || k==2 || k==3 || k==4|| k==5){
                cout<<k<<endl;
                frag= true;
                //cout<<"frag changed to 1"<<endl;
            }
        }
        //cout<<frag<<endl;
        if(frag){
            cout<<"Hello Seeker"<<endl;
        } else{
            cout<<"WTF"<<endl;
        }
        return 0;
    }

0 个答案:

没有答案
相关问题