#include "stdafx.h"
#include <iostream>

using namespace std;

int main() {
    int temp;
    string phase;
    cout << "the temperature is: ";
    cin >> temp;

    if (temp > 0 && temp < 100) {
        phase = "liquid";

    }
    else if (temp < 0)
        phase = "ice";
    else
        phase = "gas";

    cout << "the phase is :" << phase << endl;


    return 0;
}


我写的是C ++,但我无法显示可变相位。这也会停止编译器,而我无法编译它。

最佳答案

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main() {
    int temp;
    string phase;
    cout << "the temperature is: ";
    cin >> temp;

    if (temp > 0 && temp < 100) {
        phase = "liquid";

    }
    else if (temp < 0)
        phase = "ice";
    else
        phase = "gas";

    cout << "the phase is :" << phase << endl;


    return 0;
}

关于c++ - VIsual Studio说我的字符串有错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33301682/

10-11 18:01