我有一些问题导致我的代码没有任何错误地执行但是控制台一出现就消失了
I have some problem due to which my code gets executed without any errors but the console disappears as soon as it appears
我的代码:
#include<iostream>
int main()
{
int a{};
std::cout<<"enter number";
std::cin>>a;
}
此代码的构建日志:
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====
此外,当我在不同的项目上构建相同的代码时,它可以正常工作,并且控制台会一直停留到我输入数字并等待按任意键退出。
以下是我在不同项目上构建相同代码时的构建日志
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====
由于构建日志中没有明显差异,那么是什么导致了问题。
根据此文档页面 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.
因此,您可能需要控制您的设置,而不是在程序末尾添加虚假的 std::cin
。
我的代码:
#include<iostream>
int main()
{
int a{};
std::cout<<"enter number";
std::cin>>a;
}
此代码的构建日志:
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====
此外,当我在不同的项目上构建相同的代码时,它可以正常工作,并且控制台会一直停留到我输入数字并等待按任意键退出。
以下是我在不同项目上构建相同代码时的构建日志
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====
由于构建日志中没有明显差异,那么是什么导致了问题。
根据此文档页面 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.
因此,您可能需要控制您的设置,而不是在程序末尾添加虚假的 std::cin
。