c语言一键复制指定内容

#include
int main()
{
int i=0,z;
char a[5000];
printf("加密输入1 解密输入2\n");
scanf("%d",&z);
getchar();
if(z==1)
{printf("输入要加密的内容");
gets(a);

while(a[i]!='\0'){
printf("%c",a[i]+2);
i++;}}
if(z==2) {printf("输入要解密的内容");
gets(a);
while(a[i]!='\0'){
printf("%c",a[i]-2);
i++;} }
return 0;
}

每次获取加密后的内容需要先选定再ctrl+c 很麻烦,想通过操作板一键复制该内容,本人刚接触,请教各位大佬

std::string GetClipboardText()
{
// Try opening the clipboard
if (! OpenClipboard(nullptr))
... // error

// Get handle of clipboard object for ANSI text
HANDLE hData = GetClipboardData(CF_TEXT);
if (hData == nullptr)
... // error

// Lock the handle to get the actual text pointer
char * pszText = static_cast( GlobalLock(hData) );
if (pszText == nullptr)
... // error

// Save text in a string class instance
std::string text( pszText );

// Release the lock
GlobalUnlock( hData );

// Release the clipboard
CloseClipboard();

return text;
}

https://stackoverflow.com/questions/14762456/getclipboarddatacf-text

你用的是xp以上的windows?

  your_prog.exe | clip

xp或以下可以找一下
pclip.exe 或 gclip.exe

你用的Linux ?

cat samples.sh | xclip -sel clip

参考
https://www.labnol.org/software/copy-command-output-to-clipboard/2506/
https://askubuntu.com/questions/11925/a-command-line-clipboard-copy-and-paste-utility

按住ctrl 再用鼠标拉取范围 按ctrl+C 试试