Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Three questions

Three questions

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hanno25
    wrote on last edited by
    #1

    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 :)

    W S 2 Replies Last reply
    0
    • H hanno25

      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 :)

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2
      1. 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[^]
      1 Reply Last reply
      0
      • H hanno25

        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 :)

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups