im trying to make a program in c++ which would work through a txt file, and if there are duplicates in the numbers in this file, dont print them and only print out the numbers which appear once.
this is the code i've got. but what happens is it prints the file out, then prints out the second line again instead of looking for dublicates...
can anyone show me where im going wrong. fairly new to c++
// array.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
int array[100]; // creates array to hold numbers
short loop=0; //short for loop for input
string line; //this will contain the data read from the file
ifstream myfile ("problem3.txt"); //opening the file.
if (myfile.is_open()) //if the file is open
{
while (! myfile.eof() ) //while the end of file is NOT reached
{
getline (myfile,line); //get one line from the file
array[loop] = line;
cout << array[loop] << endl; //and output it
loop++;
}
for (int i = 1; i < loop; i++)
{
bool matching = false;
for (int j = 0; (j < i)&& (matching == false); j++)
{
if (array[i] == array[j])
matching = true;
}
if (!matching)
cout<< array[i] << " "
}
myfile.close(); //closing the file
}
else
cout << "Unable to open file"; //if the file is not open output
system("PAUSE");
return 0;
}