谁能帮助确定为什么这不能正确执行?如果问题与cast
Can anyone help identify why this wont execute properly? IF promblems with cast
#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被认为是一个变量。
相关文章:
- 如果 C 函数仍然可以间接执行(通过回调函数),那么将它声明为静态函数是否是一种不好的做法?
- 如果包含映射的静态库与可执行文件和动态库链接,静态映射(变量)是否会被多次释放?
- 如果函数包含静态变量,为什么编译器不执行内联?
- 如果事件在仍在执行时再次设置,RegisterWaitForSingleObject 是否会并行运行回调?
- 如果普通默认构造函数不执行任何操作,为什么我们不能使用 malloc 创建平凡可构造的对象?
- 我如何将一个变量与另一个变量进行比较,例如我想如果(var1 > var2 x 1),然后执行此 c++
- 如果我在 Linux 上更改C++动态共享库,而我的可执行程序在其上使用,会发生什么
- 如果没有带有函数签名的 rvalue 参数,是否会执行 C++ 11 中的移动语义?
- 如果我在下面的代码中使用 list 而不是 vector,为什么在我尝试在迭代器之间执行减法的行中编译失败?
- 如果发生错误,则返回错误值,否则,继续执行函数
- C 程序如果功能中的语句不执行.在逻辑上似乎是错误的
- 否则,如果语句意外执行,则表现为其他语句
- C ++程序,如果它是偶数和奇数,则不断除以2,则执行3 * K + 1
- 如果默认构造函数不执行任何操作,则目的是什么
- 如果编译器只能执行恒定折叠,则是毫无意义的
- 如果我对循环进行以下更改,执行时间是否会减少
- C++ 如果 Else 两个语句都在不应该执行的时候执行
- 构建一个可执行文件,如果是单个 cpp 文件
- 如果不在派生类实现中执行此操作,"basic_streambuf"是否会创建自己的获取/放置区域?
- 谁能帮助确定为什么这不能正确执行?如果问题与cast