Click here to Skip to main content
15,899,679 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWinAPI resources - using language packs Pin
Luy18-Mar-06 0:17
Luy18-Mar-06 0:17 
AnswerRe: WinAPI resources - using language packs Pin
Monty218-Mar-06 0:58
Monty218-Mar-06 0:58 
GeneralRe: WinAPI resources - using language packs Pin
Luy18-Mar-06 2:05
Luy18-Mar-06 2:05 
AnswerRe: WinAPI resources - using language packs Pin
Charlietoday18-Mar-06 4:27
Charlietoday18-Mar-06 4:27 
GeneralRe: WinAPI resources - using language packs Pin
Luy18-Mar-06 7:56
Luy18-Mar-06 7:56 
QuestionThree questions Pin
hanno2517-Mar-06 22:45
hanno2517-Mar-06 22:45 
AnswerRe: Three questions Pin
Waldermort17-Mar-06 23:11
Waldermort17-Mar-06 23:11 
AnswerRe: Three questions Pin
Stephen Hewitt18-Mar-06 19:00
Stephen Hewitt18-Mar-06 19:00 
The 1st one:
------------

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iterator>
using namespace std;

struct LineOfText
{
LineOfText() : m_LineNumber(1) {}

unsigned int m_LineNumber;
string m_Text;
};

ostream& operator<<(ostream &s, const LineOfText &line)
{
s << line.m_Text << " (line " << line.m_LineNumber << ")";
return s;
}

struct SortByText
{
bool operator()(const LineOfText &l, const LineOfText &r) const
{
return l.m_Text < r.m_Text;
}
};

struct IsTextEqual
{
bool operator()(const LineOfText &l, const LineOfText &r) const
{
return l.m_Text == r.m_Text;
}
};

struct SortByLine
{
bool operator()(const LineOfText &l, const LineOfText &r) const
{
return l.m_LineNumber < r.m_LineNumber;
}
};

typedef vector<LineOfText> Lines;
Lines g_Lines;

int main(int argc, char* argv[])
{
// Open the input file.
ifstream ifs("C:\\a.txt");
if (!ifs)
{
return 1;
}

// Read lines of input file into a vector.
LineOfText line;
while (getline(ifs, line.m_Text))
{
g_Lines.push_back(line);
++line.m_LineNumber;
}

// Elimiate duplicate text but keep what remains in line order.
stable_sort(g_Lines.begin(), g_Lines.end(), SortByText());
Lines::iterator new_end = unique(g_Lines.begin(), g_Lines.end(), IsTextEqual());
sort(g_Lines.begin(), new_end, SortByLine());

// Output the results.
copy(g_Lines.begin(), new_end, ostream_iterator<LineOfText>(cout, "\n"));

return 0;
}



Steve
Questionsimple question Pin
big_denny_20017-Mar-06 20:42
big_denny_20017-Mar-06 20:42 
AnswerRe: simple question Pin
Aqueel17-Mar-06 20:52
Aqueel17-Mar-06 20:52 
AnswerRe: simple question Pin
Charlietoday17-Mar-06 21:43
Charlietoday17-Mar-06 21:43 
GeneralRe: simple question Pin
big_denny_20017-Mar-06 23:11
big_denny_20017-Mar-06 23:11 
GeneralRe: simple question Pin
Waldermort17-Mar-06 23:31
Waldermort17-Mar-06 23:31 
GeneralRe: simple question Pin
Charlietoday18-Mar-06 4:22
Charlietoday18-Mar-06 4:22 
AnswerRe: simple question Pin
Hamid_RT17-Mar-06 22:12
Hamid_RT17-Mar-06 22:12 
AnswerRe: simple question Pin
Saurabh.Garg18-Mar-06 2:41
Saurabh.Garg18-Mar-06 2:41 
Questionerror LNK2001: unresolved external symbol Pin
sottos17-Mar-06 20:13
sottos17-Mar-06 20:13 
AnswerRe: error LNK2001: unresolved external symbol Pin
Waldermort17-Mar-06 22:12
Waldermort17-Mar-06 22:12 
QuestionHow to check what is the current ODBC driver version Pin
nhuythanh17-Mar-06 18:31
nhuythanh17-Mar-06 18:31 
AnswerRe: How to check what is the current ODBC driver version Pin
Paul Conrad17-Mar-06 19:06
professionalPaul Conrad17-Mar-06 19:06 
QuestionFrame Rate Pin
J512198217-Mar-06 17:57
J512198217-Mar-06 17:57 
Questiontables within richedit controls Pin
Waldermort17-Mar-06 15:26
Waldermort17-Mar-06 15:26 
QuestionQuestions about defines, includes, etc... Pin
Lord Kixdemp17-Mar-06 15:10
Lord Kixdemp17-Mar-06 15:10 
AnswerRe: Questions about defines, includes, etc... Pin
Stephen Hewitt17-Mar-06 15:16
Stephen Hewitt17-Mar-06 15:16 
GeneralRe: Questions about defines, includes, etc... Pin
Lord Kixdemp17-Mar-06 16:46
Lord Kixdemp17-Mar-06 16:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.