I'm doing a program in C ++ that takes words from a .txt file and inserts each one into an array, the problem is that you should NOT repeat any word, and I'm having complications in that part. Currently I'm only working in that part, the menu only works for the moment with 1.
/ Project.cpp: //
#include "pch.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int menu() //
{
cout << "Proyecto\n";
cout << "0. Salida\n";
cout << "1. Lectura de archivos\n";
cout << "2. Busqueda \n";
cout << "Opcion: ";
int opcion;
cin >> opcion;
return opcion;
}
void Almacenar(string Arreglo[200], int tamanio = 200)
{
string palabra;
int valor, i=0;
ifstream ficheroEntrada;
ficheroEntrada.open("Entrada.txt");
while (!ficheroEntrada.eof()) //eof para comprobar que no hemos llegado al final del archivo.
{
while (ficheroEntrada >> palabra)
{
bool comp = false;
while (i < tamanio)
{
int j = 0;
while (j <= i && comp == false)
{
if (palabra.compare(Arreglo[j])==0)
{
comp = true;
}
else
{
j++;
}
}
if (comp == false)
{
Arreglo[i] = palabra;
i++;
}
}
}
}
ficheroEntrada.close();
}
int main()
{
int opcion, tamanio = 250;
string Arreglo[200];
do
{
opcion = menu();
switch (opcion)
{
case 1: Almacenar(Arreglo, tamanio); break;
}
} while (opcion != 0);
system("pause");
return EXIT_SUCCESS;
}