April 27th, 2013, 03:09 AM
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 :
*edited for clarification purposes
using namespace std;
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.
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?
Last edited by peteandperry; April 27th, 2013 at 03:38 PM.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.