【问题标题】:Having problems debugging a C++ program调试 C++ 程序时遇到问题
【发布时间】:2023-03-25 04:22:01
【问题描述】:

我写信是说我用 C++ 编写了一个程序,可以将摄氏温度转换为华氏温度(我知道,它已经完成,这是我在 c++ 中的第一个项目),一旦我完成并正在调试,它我输入后说[ERROR] 'SYSTEM' was not declared in this scope

SYSTEM ("PAUSE")
return 0;

}

, } 之前在代码中。我搜索了如何修复它,并转到谷歌引擎中的前 10 个链接,但没有一个有效。我可以使用一些帮助,我应该获得一个新的 IDE(编译器)吗?还是我只是不擅长C++?

我的代码是:

//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 32
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
    // enter the temperature in Celsius
    int celsius;
    cout << “Enter the temperature in Celsius:”;
    cin >> celsius;
    // calculate conversion factor for Celsius
    // to Fahrenheit
    int factor;
    factor = 212 - 32;
    // use conversion factor to convert Celsius
    // into Fahrenheit values
    int fahrenheit;
    fahrenheit = factor * celsius/100 + 32;
    // output the results (followed by a NewLine)
    cout << “Fahrenheit value is:”;
    cout << fahrenheit << endl;
    // wait until user is ready before terminating program
    // to allow the user to see the program results
    system(“PAUSE”);
    return 0;
}

【问题讨论】:

标签: c++ debugging ide


【解决方案1】:

您使用的是智能引号而不是直引号,这会阻止您的程序编译,但除此之外程序运行良好。

使用" 而不是

【讨论】:

  • 谢谢!程序最终没有错误,系统(“暂停”)最终工作;程序编译好了!
  • 没问题!快乐编码!要接受答案,请点击选票下方的复选标记。这有助于其他用户针对他们可能遇到的问题找到已回答的问题。
  • @ThatAid3n 忘记在最后一个标记你了,哎呀
  • @ThatAid3n 不要忘记将此答案标记为已接受!这将使阅读本文的其他人更容易找到正确的答案,并且会奖励 TNTFreaks 以花时间帮助您的声誉。 :)
【解决方案2】:

@TNTFreaks - 打败我。

另外,system 调用不安全,您可能想尝试使用另一种方法(我个人使用cin.get(); cin.ignore();)您可以尝试查看: Alternative to system("PAUSE")? ---- system("pause"); - Why is it wrong? ---- System() calls in C++ and their roles in programming.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多