谁能帮助确定为什么这不能正确执行?如果问题与cast

Can anyone help identify why this wont execute properly? IF promblems with cast

本文关键字:执行 如果 问题 cast 不能 帮助 为什么      更新时间:2023-10-16
#include <iostream>
#include <fstream>
using namespace std;
int run_t = 0;
char q_mos;
char i_pstring;
int main () {
    cout << "Would you like to write to the temporary datapcku database?nSelect Y/Nn";
    cin >>  q_mos;
    if(q_mos = char(Y)){ //for some reason I am having time resolving the value of Y
        while(run_t=0){
            cout << "Running Input Operations.n";
            cout << "Please provide me with a Question so it can be achrived in the Active DB(Directory)n";
            cin >> i_pstring;
            cout << "Please tell me the answer...n";
            cout << i_pstring;
        }
        run_t=1;
    } else {
        run_t=1;
        cout << "Booting into main operations...n";
    }
    cout << "At diagnostic Boot menu, prepare for diagnostic on system config orginaztional routines.n";
    ofstream binlib;
    binlib.open ("datapcku.bin", ios::app | ios::binary );
    binlib << "Writing this to a file.n";
    binlib.close();
    while(1){}
    return 0;
}

很明显,我想使用我的run_t变量来控制完整的程序可操作性,但我有时间执行q_mos到cin输入,我无法理解为什么逻辑似乎是失败的,因为在q_mos比较之后的简单while循环中不会执行甚至一个我进入块内。我需要将q_mos转换为字符串吗?什么会影响run_t变量while循环

有几个地方不对。

在您的if(q_mos = char(Y))语句中,

a)你是赋值,而不是比较(使用==代替=)。这也适用于你的while循环。

b)将char(Y)替换为'Y',因为您正在传递它,Y被认为是一个变量。

相关文章: