我目前正在尝试学习C ++,我编写了以下程序。它确实应该成功,但它会自动退出。我已经尝试在最后放置一个cin
,当它没有工作时,我放了一个getChar()
并且它不会等待任何输入。要明确的是,我没有接受过关于C ++的正规教育,这个问题让我很难过。我试过谷歌搜索它,但所有出现的是它告诉我使用我已经尝试过的任何一件事。我已经注释了cin
断点,以显示我放置它们的位置。
正如我之前所说,该程序的实际代码如下。下面是调试日志。
为了它的价值,我使用Visual Studio来实现这个目标。
编辑:这不是一个重复的问题,因为我希望能够使用实际的可执行文件,双击它并让它等待我按键直到它退出。有了这个程序,即使我转到实际的可执行文件,它仍会自动退出。
该计划的代码:
#include <iostream>
#include <string>
using namespace std;
// Declare variables for intro
string intro = "Please enter your score.\n";
string prompt = ">>> ";
string nl = "\n";
// Declare grade calculation variables
int initial_grade = 0;
bool temp;
// Declare variables for perfection test
string perfect_score = "You scored perfectly, congratulations!\n";
void perfection_test() {
switch (initial_grade) {
case 100:
cout << perfect_score;
//cin;
}
//cin;
}
int main() {
cout << intro << prompt;
cin >> initial_grade;
cout << nl;
//cin;
perfection_test();
//cin;
}
调试:
'GradingProgram.exe' (Win32): Loaded 'C:\Users\student\Desktop\khush\GradingProgram\Debug\GradingProgram.exe'. Symbols loaded.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
The thread 0x134c has exited with code 0 (0x0).
The thread 0x2110 has exited with code 0 (0x0).
The thread 0x210c has exited with code 0 (0x0).
The program '[9092] GradingProgram.exe' has exited with code 0 (0x0).