所以我的目标是创建一个函数,将部分填充的字符数组作为形式参数,并从数组中删除所有重复的字母。所以我只需要读取一个 .txt 文件,其内容类似于“11 ABC abca A ggt”,然后让程序吐出“ABC abcg t”
截至目前,我的程序吐回“1 ABC abc”
我真的很感激这方面的任何帮助。
这是我所拥有的...
#include <iostream>
#include <fstream>
using namespace std;
bool deleterepeat( char arraytocheck[], char lettertocheck, int length)
{
bool onlistflag = false;
{
for (int i = 0; i < length; i++)
{
if (arraytocheck[i] == lettertocheck)
{
onlistflag = true;
}
}
}
return onlistflag;
}
int main()
{
const int MAX = 15;
char inFile[MAX];
char clearedList[MAX];
int clearedlength = 0;
cout << "Choose a file: ";
cin.getline(inFile, 15);
ifstream in(inFile);
if(!in) {
cout << "Cannot open input file.\n";
return 1;
}
while(in) {
in.getline(inFile, MAX);
for (int i = 0; i < MAX; i++)
{
in >> inFile[i];
}
for (int i = 0; i < MAX; i++)
{
if (deleterepeat(clearedList, inFile[i], i) == false)
{
clearedList[clearedlength] = inFile[i];
clearedlength++;
}
}
for (int i = 0; i < clearedlength; i++)
{
cout << clearedList[i] << " ";
}
if(in) cout << inFile << endl;
}
cout << endl;
cin >> inFile;
in.close();
return 0;
}