txtファイルを介して機能するプログラムをc ++で作成しようとしています。このファイルの数字に重複がある場合は、それらを印刷せず、一度表示される数字のみを印刷してください。
これは私が持っているコードです。しかし、ファイルを印刷してから、重複を探す代わりに2行目を再度印刷します...
どこが間違っているのか誰か教えてください。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;
}