Visual Studios - C++控制台立即打开和关闭

Visual Studios - C++ Console Opening & Closing Right Away

本文关键字:Studios C++ 控制台 Visual      更新时间:2023-10-16

尝试运行这个程序,但每当它运行时,它都会迅速打开并立即关闭,不允许我与之交互。我做错了什么才能打开和关闭它?

下面是我的程序,我确定我做错了什么。

感谢您的帮助!

驱动程序.cpp

#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    char Anagram();
}

字谜.cpp

#include<string>
#include<algorithm>
#include<iostream>
#include "Anagram.h"
using namespace std;
char Anagram()
{
string FirstAnagram, SecondAnagram;
char keep_going;
do
{
    cout << "Enter word one: ";
    cin >> FirstAnagram;
    cout << "Enter word two: ";
    cin >> SecondAnagram;
    sort(FirstAnagram.begin(), FirstAnagram.end());
    sort(SecondAnagram.begin(), SecondAnagram.end());
    if (FirstAnagram == SecondAnagram)
    {
        cout << "They are anagrams of each other.";
    }
    else
    {
        cout << "They are not anagrams of each other.";
    }
    cout << "nnTry another?";
    cin >> keep_going;
}
while (keep_going == 'y');
return 0;
}

字谜.h

char Anagram();

试试这个:

#include<string>
#include<algorithm>
#include<iostream>
#include "Anagram.h"  // add this
using namespace std;
int main()
{
    char ch = Anagram();  // call the function like this
}

尝试将其添加到main函数的末尾:

std::cout << "Press Enter to close application.n";
std::cin.ignore(10000, 'n');