Я делаю консольное приложение для обучения.
Когда я отлаживаю код ниже, он закрывается перед отображением
std::cout << e << std::endl;
Если я переместил целое число e и его вывод до std::cout << "Enter a number:";
, он будет работать нормально, но при перечислении, как показано ниже, работает только его ввод, и консоль закрывается сама.
#include "stdafx.h"
#include <iostream>
int raisemath()
{
std::cout << "Enter an integer: "; // ask user for an integer
int a; // allocate a variable to hold the user input
std::cin >> a; // get user input from console and store in variable a
return a; // return this value to the function's caller (main)
}
int main()
{
int number;
std::cout << "Enter a number:";
std::cin >> number;
std::cout << "You entered " << number << std::endl;
int e = raisemath();
std::cout << e << std::endl;
return 0;
}
Я хочу знать, почему?