// RemoveDuplicatesCSVconsole.cpp: определяет точку входа для консольного приложения.
#include <stdio.h>
#include "stdafx.h"
#include <wchar.h>
#include <vector>
#include <string>
#include <iterator>
#include <array>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <Windows.h>
#include <io.h>
#include <fcntl.h>
const int CharCount = 255;
wchar_t *FileIn = new wchar_t[CharCount];
wchar_t *FileOut = new wchar_t[CharCount];
wchar_t *Title = new wchar_t[CharCount];
wchar_t *LogFile = new wchar_t[CharCount];
int wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )
{ ////////////////////переводим в Юникод
_setmode(_fileno(stdout), _O_U16TEXT);
_setmode(_fileno(stdin), _O_U16TEXT);
_setmode(_fileno(stderr), _O_U16TEXT);
////////////////////переводим в Юникод
system("mode con cols=100 lines=50"); //размер окна, вывод количества строк в консоль
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD size{ 100,100 };//символов строки, строк
SetConsoleScreenBufferSize(hout, size);//размер буфера
///////////////////////////////////
static wchar_t* prog_name = argv[0];
int Log = 0;
int Caption = 0;
std::wcout << L"Created by 2017 Bedvit (bedvit@mail.ru)\n";
std::wcout << L"Delete duplicate rows in the .CSV file (With or without a title(choose zize), ANSI, text separator - (\\n)(
)(U+000A)\n";
if (argc > 2) {
FileIn = argv[1];
std::wcout << L"\nEnter Full Name CSV In: ";
wprintf(L"%s", FileIn); //http://www.c-cpp.ru/content/printf
FileOut = argv[2];
std::wcout << L"\nEnter Full Name CSV Out: ";
wprintf(L"%s", FileOut);
if (argc > 3) Caption = _wtoi(argv[3]);
std::wcout << L"\nEnter the number of header lines: ";
wprintf(L"%i\n", Caption);
if (argc > 4) Log = _wtoi(argv[4]);
}
else {
std::wcout << L"\nEnter Full Name CSV In: ";
//std::cin >> FileIn;//scanf("%[^\r\n]", FileIn);//fgets(FileIn, 255, stdin);//std::getline(std::cin, FileIn);
fgetws(FileIn, CharCount, stdin);
FileIn[wcscspn(FileIn, L"\n")] = 0;
wprintf(L"Enter Full Name CSV Out: ");
fgetws(FileOut, CharCount, stdin);
FileOut[wcscspn(FileOut, L"\n")] = 0;
std::wcout << L"Enter the number of header lines: ";
fgetws(Title, CharCount, stdin);
Title[wcscspn(Title, L"\n")] = 0;
Caption = _wtoi(Title);
Log = 1;
}
if (Caption < 0) {
bool err = true;
wprintf(L"\nERROR: the number of header lines\n\n");
_wsystem(L"pause");
return 1;
}
if (wcslen(FileIn) < 5 || wcslen(FileOut) <5) {
bool err = true;
wprintf(L"\nERROR: Full Name CSV\n\n");
_wsystem(L"pause");
return 1;
}
std::ifstream file1(FileIn, std::ios::in | std::ios::binary);
if (!file1.is_open()) {
wprintf(L"\nERROR: Full Name CSV In\n\n");
_wsystem(L"pause");
return 1;
}
std::ofstream file2(FileOut, std::ios::out | std::ios::binary);
if (!file2.is_open()) {
wprintf(L"\nERROR: Full Name CSV Out\n\n");
_wsystem(L"pause");
return 1;
}
unsigned long long time0 = clock(); // начальное время
wprintf(L"\nStart...\n");
std::vector<std::string> DataIn;
std::istream_iterator<std::string> input_iterator(file1), end;
std::copy(input_iterator, end, std::back_inserter(DataIn));
unsigned long long time1 = clock();
wprintf(L"File: Open, rows = %zi, time = %6.3f\n", DataIn.size(),(double)(time1 - time0) / 1000);
std::sort(DataIn.begin() + Caption, DataIn.end());
unsigned long long time2 = clock();
wprintf(L"File: Sort, time = %6.3f\n", (double)(time2 - time1) / 1000);
std::vector<std::string>::iterator it;
it = std::unique(DataIn.begin() + Caption, DataIn.end());
unsigned long long time3 = clock();
wprintf(L"File: Unique, time = %6.3f\n", (double)(time3 - time2) / 1000);
DataIn.resize(std::distance(DataIn.begin(), it));
unsigned long long time4 = clock();
wprintf(L"File: Resize, time = %6.3f\n", (double)(time4 - time3) / 1000);
std::ostream_iterator<std::string> output_iterator(file2, "\n");// std::ostream_iterator<std::string> output_iterator(output_file, "\n");
std::copy(DataIn.begin(), DataIn.end(), output_iterator);//std::copy(example.begin(), example.end(), output_iterator);
file1.close();
file2.close();
unsigned long long time5 = clock();
wprintf(L"File: Save, rows = %zi, time = %6.3f\n", DataIn.size(),(double)(time5 - time4) / 1000);
wprintf(L"End\nTotal Time = %6.3f(sec)\n", (double)(time5 - time0) / 1000);
if (Log != 0) _wsystem(L"pause");
return 0; |