尝试运行此程序,但无论何时运行都会立即打开并立即关闭而不允许我与之交互。我把它打开和关闭的错误是什么?
以下是我的计划,我确定我做错了。
感谢您的帮助!
Driver.cpp
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
char Anagram();
}
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 << "\n\nTry another?";
cin >> keep_going;
}
while (keep_going == 'y');
return 0;
}
Anagram.h
char Anagram();
答案 0 :(得分:3)
试试这个:
#include<string>
#include<algorithm>
#include<iostream>
#include "Anagram.h" // add this
using namespace std;
int main()
{
char ch = Anagram(); // call the function like this
}
答案 1 :(得分:0)
尝试将此添加到main
功能的末尾:
std::cout << "Press Enter to close application.\n";
std::cin.ignore(10000, '\n');