how to i copy to clipboard so i can use it as ctrl v

sorry if i dont make sense. im still confused on how to explain what i want.

so basically, if they enter in a text in a console, it would be saved to their clipboard which can later be used when you type CTRL v.

can somebody help me out?

thanks
closed account (zb0S216C)
You would have to use the OS's API for this. For Windows, see this link: http://msdn.microsoft.com/en-us/library/ms648709(VS.85).aspx

Wazzak
OK. I understood. You want to write to the clipboard.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<windows.h>
void setClipboard (char* str )
{ 
HGLOBAL hText;
char* pText; 
hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVABLE,100) ; 
pText = ( char * ) GlobalLock ( hText );
strcpy (pText , str);
GlobalUnlock(hText) ; OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_TEXT,hText);
CloseClipboard(); 
}

char* getClipboard()
{
OpenClipboard ( NULL );
HANDLE str = GetClipboardData (CF_TEXT ) ;
CloseClipboard ( ) ;
LPVOID lptstr = GlobalLock ( str );
return (char*)str;
}

int main()
{
cout<<"Your input will be saved to clipboard and you can paste it: ";
string str;
cin>>str;
setClipboard(str.c_str());
cout<<endl<<"Saved";
cout<<endl<<"Data in clipboard is: "<<getClipboard(); 
return 0;
}


In windows, it should work :)
Last edited on
Topic archived. No new replies allowed.