reverse the string sequence in a string buffer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 9 of 9

Thread: reverse the string sequence in a string buffer

Threaded View

  1. #1
    Join Date
    Apr 2013

    reverse the string sequence in a string buffer

    hello again! I made a simple little program that takes text from the clipboard, and spits out all the lines I've copied one at a time (so my program can analyze it).

    everything works perfectly, except, it spits it own in the wrong order, I want it to spit out from bottom to top. but currently it spits out the data from top to bottom. here is my code :

    #include <iostream>
    #include <Windows.h>
    #include <string>
    #include <sstream>
    using namespace std;
    int main()
         HANDLE clip; // assigns the var. clip to hold a handle ID.
         if (OpenClipboard(NULL)) // checks to see if there is data in the clipboard & opens it
              clip = GetClipboardData(CF_TEXT); // gets the handle of the clipboard.
              CloseClipboard(); //closes the clipboard (be tidy! lol)
         string text; // make the var "text" string type.
         text = (char*)clip; // grabs the strings from the clipboard and stores it in "text"
         cout << (char*)clip << endl << endl; // shows me whats currently in the clipboard
         std::istringstream f(text); // splits the string into it's seperate lines.
         std::string line; // <- the variable that will hold the current line
         while (std::getline(f, line)) // Uses sstream **** I want this loop to run backwards! ******
              std::cout << line << std::endl; //show the current line to be inspected
              // ADD DIAGNOSING CODE HERE.
              Sleep(1000); // makes it wait a bit before posting the line so I can see it one by one.
    *edited for clarification purposes

    the **** I want this loop to run backwards! ****** part is, like it say's what I want to work backwards.
    where as I know how to flip a while loop like this: while(x < 5), I have No idea how to flip a loop like the one I'm using.

    anyone have any Idea's how I can do this?
    thank you!
    Last edited by peteandperry; April 27th, 2013 at 02:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center