Search code examples
c++exitcodelite

I have some problem due to which my code gets executed without any errors but the console disappears as soon as it appears


my code:

#include<iostream>
int main()
{
    int a{};
    std::cout<<"enter number";
    std::cin>>a;
}

the build log for this code:

C:\WINDOWS\system32\cmd.exe /C C:/MinGW/bin/mingw32-make.exe -j8 SHELL=cmd.exe -e -f  Makefile
"----------Building project:[ ConstructorsAndDestructors - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/AT/Documents/OOP_basics/Constructors&Destructors'
C:/MinGW/bin/g++.exe  -c  "C:/Users/AT/Documents/OOP_basics/Constructors&Destructors/main.cpp" -g -O0 -Wall  -o Debug/main.cpp.o -I. -I.
C:/MinGW/bin/g++.exe -o Debug/ConstructorsAndDestructors @"ConstructorsAndDestructors.txt" -L.
mingw32-make.exe[1]: Leaving directory 'C:/Users/AT/Documents/OOP_basics/Constructors&Destructors'
====0 errors, 0 warnings====

Furthermore, when I build the same code on a different project, it works correctly, and the console stays till I input the number and waits for pressing any key to exit.

Following is the build log when I build the same code on a different project

C:\WINDOWS\system32\cmd.exe /C C:/MinGW/bin/mingw32-make.exe -j8 SHELL=cmd.exe -e -f  Makefile
"----------Building project:[ AcessingClassMembers - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/AT/Documents/OOP_basics/AcessingClassMembers'
C:/MinGW/bin/g++.exe  -c  "C:/Users/AT/Documents/OOP_basics/AcessingClassMembers/main.cpp" -g -O0 -Wall  -o Debug/main.cpp.o -I. -I.
C:/MinGW/bin/g++.exe -o Debug/AcessingClassMembers @"AcessingClassMembers.txt" -L.
mingw32-make.exe[1]: Leaving directory 'C:/Users/AT/Documents/OOP_basics/AcessingClassMembers'
====0 errors, 0 warnings====

As there's no visible difference in the build logs, then what is causing problem.


Solution

  • According to this documentation page https://wiki.codelite.org/pmwiki.php/Main/ProjectSettings

    Project Settings

    [...]
    When executing your program inside CodeLite, it actually runs in a terminal. The checkbox Pause when execution ends, which is ticked by default, means that the terminal stays open after closing the program; so any error messages or program output remains visible. If you don't need this, you can untick the box.

    So, you may need to control your settings, rather than adding a spurious std::cin at the end of your program.