Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ';如果';即使变量为false也会执行_C++ - Fatal编程技术网

C++ ';如果';即使变量为false也会执行

C++ ';如果';即使变量为false也会执行,c++,C++,所以,我知道在这个网站上有很多与此相关的问题,但我找不到一个与我的问题类似的问题 cout<<"Please enter one or more floating point numbers"<<endl<<"When finished, enter 'q'"<<endl; while(!done) { cin>>Next; char letter; double temp; letter=Next[

所以,我知道在这个网站上有很多与此相关的问题,但我找不到一个与我的问题类似的问题

cout<<"Please enter one or more floating point numbers"<<endl<<"When finished, enter 'q'"<<endl;

while(!done)

{
    cin>>Next;
    char letter;
    double temp;
    letter=Next[0];
    if (letter=='q')
        done=true;

    if (!done)
       temp = stod(Next);
       cout<<"temp is "<<temp<<" Next is "<<Next<<endl;
       localdata.push_back(temp);
}
因此,问题是,当标准输入为
q
时,
done
的值应更改为
true
,但如果(!done)执行,则下一个
仍然,而它不应执行


有什么问题吗?我知道这一定是很明显的事情,但我不能把我的手指放在上面

您省略了大括号。在C++中,没有括号,<代码>如果只取第一行。您应该使用大括号:

if (!done) {
    temp = stod(Next);
    cout<<"temp is "<<temp<<" Next is "<<Next<<endl;
    localdata.push_back(temp);
}
如果(!完成){
温度=stod(下一个);

coutC++不是Python。只有
temp=…
内部,如果
,其他的在外部,并且总是执行。记住{}如果使用其他方法,你有两个IFS,它总是触发。C++使用卷轴表示<代码>如果< /Cord>块。缩进代码不做任何事情。“SamiKuhmonen,非常感谢,这很快!新手错误side@user1993一般来说,永远不要用另一种语言来解决C++中的问题。即使是看起来像C++的98%种语言,也不要使用U语言。把它们作为编写代码或如何编写C++代码的指南。
if (!done) {
    temp = stod(Next);
    cout<<"temp is "<<temp<<" Next is "<<Next<<endl;
    localdata.push_back(temp);
}