vendredi 3 février 2023

color changing happens all at once in c++

i am making a program that is supposed to show you the stations to the sofia metro and i tried making it colorized, but then it turns out that it just shows the color of the last thing printed. i tried it on cxxdroid and it worked fine but on codeblox and several online compilers the issue seems to persist. what i

imagined happening is like the image attatched here: (https://i.stack.imgur.com/u03Fj.png) vs what actually ended up happening: (https://i.stack.imgur.com/q1EqZ.png)

so my (simplified ofc) code looks like this:

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    cout<<"chose on of the following lines to show their stations: "<<endl<<flush;
    system("color 40");
    cout<<"line one: Liulin  - Mladost (Business Park - Slivnitsa)"<<endl<<flush;
    system("color 90");
    cout<<"line 2: Nadejda - Lozenets (Obelia - Vitosha)"<<endl<<flush;
    system("color A0");
    cout<<"line 3: Ovcha Kupel - Hadji Dimitar (Gorna Bania - Hadji Dimitar)"<<endl<<flush;
    system("color 60");
    cout<<"line 4: Obelia - Sofia Airport"<<endl<<flush;
    system("color 00");
    cout<<"enter 5 for all 5 lines to be shown at once"<<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire