Read a string then copy it to clipboard

May 10, 2011 at 3:34am
I am working on a personal project and have encountered an obstacle. My task is simply to read a string and then copy that string to the clipboard but I am not able to get these 2 tasks merged.

To read a string:
string name;
getline (cin,name);

To copy to clipboard (Code found online -- working):
const char* output = "oooo";
const size_t len = strlen(output) + 1;
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hMem), output, len);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();


However, as I am not an expert I have not been able to combine these 2 tasks. Any help is appreciated
May 10, 2011 at 3:38am
The method c_str() of std::string will return a char* of the string, and size() will return the number of characters in it.
May 10, 2011 at 3:40am
Thank you for your help. How exactly would your information tie into this?
Topic archived. No new replies allowed.