cpp中的清除控制台

时间:2019-10-09 10:36:53

标签: c++ console clear

system(“ cls”)无法正常工作,它无需打印任何内容即可完成程序。 如果没有该程序,该程序将运行,但如果未清除所有先前的打印内容,则在控制台中的外观将不佳。我曾尝试将命令放在不同的位置,但是程序放置在何处都没关系。

#include <iostream>
#include <math.h>
#include <windows.h>
#include <stdlib.h>

using namespace std;

float c, temp, eq;
char odp = 't';

int main()
{
    do
    {
        cout << "Choose from what value you'd like to convert." << endl;
        cout << "Celsius = 1   ;   Fahrenheit = 0" << endl;
        cin >> c;

        if (c==1)
        {
           cout << "Insert Celsius value: ";
           cin >> temp;

           eq = temp * 1.8 + 32;
           cout << "It is " << eq << " degrees Fahrenheit." << endl;
           cout << "If you want to continue converting please insert: t" << endl;
           cin >> odp;
        }
        else if (c==0)
        {
            cout << "Insert Fahrenheit value: ";
            cin >> temp;

            eq = (temp * 1.8) - 32;
            cout << "It is " << eq << " degrees Celsius." << endl;
            cout << "If you want to continue converting please insert: t" << endl;
            cin >> odp;
        }
        else
        {
            cout << "Please choose correctly" << endl;
        }
    }
    while(odp = 't');

return 0;
}

我如何放置命令并立即完成整个程序

#include <iostream>
#include <math.h>
#include <windows.h>
#include <stdlib.h>

using namespace std;

float c, temp, eq;
char odp = 't';

int main()
{
    do
    {
        cout << "Choose from what value you'd like to convert." << endl;
        cout << "Celsius = 1   ;   Fahrenheit = 0" << endl;
        cin >> c;

        if (c==1)
        {  system("cls")                                           //here
           cout << "Insert Celsius value: ";
           cin >> temp;

           eq = temp * 1.8 + 32;
           cout << "It is " << eq << " degrees Fahrenheit." << endl;
           cout << "If you want to continue converting please insert: t" << endl;
           cin >> odp;
        }
        else if (c==0)
        {
            cout << "Insert Fahrenheit value: ";
            cin >> temp;

            eq = (temp * 1.8) - 32;
            cout << "It is " << eq << " degrees Celsius." << endl;
            cout << "If you want to continue converting please insert: t" << endl;
            cin >> odp;
        }
        else
        {
            cout << "Please choose correctly" << endl;
        }
    }
    while(odp = 't');

return 0;
}

我真的不知道,谢谢您的答复

0 个答案:

没有答案