,   CyberForum.ru

set <string> - C++


 
C++ Vector ++(2) http://www.cyberforum.ru/cpp-beginners/thread928278.html
(), Circle, Rectangle , ...
C++ .cpp .cpp ? , ( , IDE - Microsoft Visual Studio 2010 http://www.cyberforum.ru/cpp-beginners/thread928238.html
C++
netbeans + cygwin . TCPClient.cpp // TCPClient.cpp : Defines the entry point for the application. // #include "stdafx.c"
C++ dll dll
, : dll dll , . ...
C++ main() , ? http://www.cyberforum.ru/cpp-beginners/thread928193.html
F()? class A { public: bool F(int &a, int &b) { return a<b; } }; int main() {
C++ C++ ifstream/ofstream / eof() ...

tramp_1-3
14 / 14 / 1
: 13.10.2012
: 432

set <string> - C++

24.07.2013, 20:35. 1569. 12
( )

, - , . - , .
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <set>
#include <fstream>
#include <cstdlib>
#include <vector>
 
using std :: vector;
using std :: set;
using std :: cout;
using std :: cin;
using std :: string;
using std :: cerr;
using std :: ifstream;
using std :: ofstream;
 
void  NumberOfLines (int argc, char * argv [], int entries []);
 
int main (int argc, char * argv []) {
    if (argc == 1) {
        cerr << "Usage: files for input, last for output\n";
        exit (1);
    };
    int quantity = argc - 2;         //êîëè÷åñòâî ô*éëîâ
    int * entries = new int [quantity];   //ì*ññèâ, â êîòîðîì õð**èòñÿ êîëè÷åñòâî ç*ïèñåé (ñòðîê) â ê*æäîì ô*éëå
    NumberOfLines (argc, argv, entries);  //ôó*êöèÿ ïîäñ÷¸ò* êîëè÷åñòâ* ç*ïèñåé
    char ch;
    std :: ostream_iterator <string>  show (cout, "\n");
    vector <set <string> > lists;    //êî*å÷*ûé ì*ññèâ ç*ïèñåé
    int emptylists = 0; //êîëè÷åñòâî ïóñòûõ ô*éëîâ, ÷òîáû ïðè âûâîäå lists [i] *å âîç*èê*ëî îøèáîê
    ifstream inputfile;
    for (int i = 0; i < quantity; i++) {        //ïðî÷èò*òü âñå ô*éëû, êðîìå ïåðâîãî è ïîñëåä*åãî
        if (entries [i] != 1) {
            inputfile.open (argv [i + 1]);                     //ó âõîä*îãî argv [i + 1] ô*éë* entries[i] ñòðîê
            set <string> tempset;                   //âðåìå**ûé ñïèîê äëÿ õð**å*èÿ òåêóùåãî îáð*á*òûâ*åìîãî ô*éë*
            for (int j = 0; j < entries[i]; j++) {  // ïðî÷èò*òü âñå ñòðîêè argv [i + 1] ô*éë*                   
                string tempstr;                     //âðåìå***ÿ ñòðîê* äëÿ õð**å*èÿ òåêóùåé îáð*á*òûâ*åìîé ñòðîêè
                while (inputfile.get (ch) && ch != '\n') {
                    tempstr += ch;
                };
                tempset.insert (tempstr);
            };
            lists.push_back (tempset);
            cout << "\"" << argv [i+1] <<"\" list:\n";
            copy (lists [i - emptylists].begin (), lists [i - emptylists].end (), show);
            cout << "\n";
            inputfile.clear ();
            inputfile.close ();
        }
        else  {
            emptylists++;
            cout << "\"" << argv [i+1] <<"\" list is empty.\n\n";
            continue;
        };
    };
    cout << "Result:\n";
    int v = 0;
    set <string> resultlist;
    vector <set <string> > :: iterator viter;
    for ( viter = lists.begin (); viter != lists.end (); viter++, v++)
        merge (lists [v].begin (), lists [v].end (), resultlist.begin (), resultlist.end (), std :: inserter (resultlist, resultlist.begin ()));
    copy (resultlist.begin (), resultlist.end (), show);
    cout << "\n";
    ofstream outputfile;
    outputfile.open (argv [argc], std :: ios_base :: trunc | std :: ios_base :: app);
    /*std :: ostream_iterator <string> output (outputfile, "\n");
    copy (resultlist.begin (), resultlist.end (), output);
    */
    /*set <string> :: iterator  siter;
    for (siter = resultlist.begin (); siter != resultlist.end (); siter++)
        outputfile << *siter << "\n";
    */
    system ("pause");
    return 0;
};
 
void  NumberOfLines (int argc, char * argv [], int entries []) {
    int quantity = argc - 2;
    for (int i = 0; i < quantity; i++)
        (entries [i]) = 1;
    ifstream inputfile;
    for (int i = 0; i < quantity; i++) {    //ïîäñ÷¸ò êîëè÷åñòâ* ç*ïèñåé â ê*æäîì ô*éëå
        inputfile.open (argv [i + 1]);
        char ch;
        while (inputfile.get (ch))
            if ( ch == '\n')
                (entries [i])++;
        if (ch == '\n')     //åñëè â êî*öå ô*éë* ïðîñòî ïóñò*ÿ ñòðîê*, óìå*üøèòü êîëè÷åñòâî ñòðîê
            (entries [i])--;
        inputfile.clear ();
        inputfile.close ();
    };
    return;
};
0
? .
 
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
@Mail.ru