0

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.

anonymous38653
  • 393
  • 4
  • 16
  • It seems that your code is compiled and linked, but it's never executed. What does your Makefile look like? – Bob__ Apr 11 '20 at 09:06
  • @Bob__ I am using codelite IDE and I don't know about Makefile – anonymous38653 Apr 11 '20 at 09:09
  • 2
    The console has no reason to stay open when main has been exited. Try adding `std::cin.get();` as a second function call. – George Apr 11 '20 at 09:29
  • @George now, I've edited the question, but the problem still exists – anonymous38653 Apr 11 '20 at 09:38
  • As Bob points out, the first line of your build log says you are building with Makefile. That could affect the result. – stark Apr 11 '20 at 11:18
  • @stark how do I do it differently? – anonymous38653 Apr 11 '20 at 11:31
  • *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.* How does the build log look for the other project ? – Saurabh P Bhandari Apr 11 '20 at 11:35
  • @SaurabhPBhandari thanks for asking that question, I've updated the question – anonymous38653 Apr 11 '20 at 11:43
  • Make sure you are actually executing the program you just compiled. In order to do that, open a console manually, navigate to the executable, verify that it has the expected timestamp, and then execute it manually. This has the nice side effect that you see any error messages, including from Windows ("could not find dll xy" etc.). – Peter - Reinstate Monica Apr 11 '20 at 13:10

1 Answers1

1

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.

Bob__
  • 12,361
  • 3
  • 28
  • 42