Three questions
-
Hi, I have some questions, concerning three different things: 1.: if there is a text file with some identical lines in it, how can I find out, if there are identical lines and how can I delete these identical lines except of the first one? 2.: how can I replace the "GOTO" by an other statement? I already tried it with a simple "return", but that doesn't work. _eins: if (m_dlgSheet.DoModal() == IDOK) { condition 1= ... condition 2 = ... if(condition1 != true&& condition2 != true) { goto _eins; } } 3: do somebody know, how to implement a "zoom window"-function? Having this function, the user should be albe to draw with a left-mouse-klick a rectangle; while LMouseButtonUp, the content of the chosen rectangle should be enlarged to the whole size of the window. Maybe somebody knows a link or even source-code for this problem? Hanno :)
-
Hi, I have some questions, concerning three different things: 1.: if there is a text file with some identical lines in it, how can I find out, if there are identical lines and how can I delete these identical lines except of the first one? 2.: how can I replace the "GOTO" by an other statement? I already tried it with a simple "return", but that doesn't work. _eins: if (m_dlgSheet.DoModal() == IDOK) { condition 1= ... condition 2 = ... if(condition1 != true&& condition2 != true) { goto _eins; } } 3: do somebody know, how to implement a "zoom window"-function? Having this function, the user should be albe to draw with a left-mouse-klick a rectangle; while LMouseButtonUp, the content of the chosen rectangle should be enlarged to the whole size of the window. Maybe somebody knows a link or even source-code for this problem? Hanno :)
- there are many ways to do this, personaly I would read the file into a buffer line by line. Look at the basic_string or CString in MFC, these classes make it easy to compare to lines "strings" of text. 2) GOTO is an ugly statement. try: while (!statement1 && !statement2) { .... } but beware that you could quite likely end up in an endless loop, you should have some sort of check in there and to exit the while loop use the break command while (...) { if (endless_loop) break; // or return; will exit the function } 3) maybe somebody else could better help you here. But here[^] is a project that might start you on the right track. You should also look on MSDN for mouse input functions here[^]
-
Hi, I have some questions, concerning three different things: 1.: if there is a text file with some identical lines in it, how can I find out, if there are identical lines and how can I delete these identical lines except of the first one? 2.: how can I replace the "GOTO" by an other statement? I already tried it with a simple "return", but that doesn't work. _eins: if (m_dlgSheet.DoModal() == IDOK) { condition 1= ... condition 2 = ... if(condition1 != true&& condition2 != true) { goto _eins; } } 3: do somebody know, how to implement a "zoom window"-function? Having this function, the user should be albe to draw with a left-mouse-klick a rectangle; while LMouseButtonUp, the content of the chosen rectangle should be enlarged to the whole size of the window. Maybe somebody knows a link or even source-code for this problem? Hanno :)
The 1st one: ------------ #include #include #include #include #include #include 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 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(cout, "\n")); return 0; } Steve