gpt4 book ai didi

c++ - VIsual Studio 说我在字符串中有错误

转载 作者:行者123 更新时间:2023-11-28 06:00:57 25 4
gpt4 key购买 nike

#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++,但无法显示变量 phase 。这也会停止编译器,我无法编译它。

最佳答案

#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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com