Jump to content
Maximus

C++ clipboard

Recommended Posts

am codul urmator :


#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>

using namespace std;

int main () {
string line;
ifstream myfile ("1.txt");
getline (myfile,line);

HGLOBAL hText;
char *pText;
hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100);
pText = (char*)GlobalLock(hText);
strcpy(pText, line);
GlobalUnlock(hText);

OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_TEXT, hText);
CloseClipboard();
myfile.close();
return 0;
}

cand dau debug imi zice :

Error	1	error C2664: 'strcpy' : cannot convert parameter 2 from 'std::string' to 'const char *'	c:\users\max\documents\visual studio 2010\projects\test\test\test.cpp	21	1	test

2 IntelliSense: no suitable conversion function from "std::string" to "const char *" exists c:\users\max\documents\visual studio 2010\projects\test\test\test.cpp 21 16 test

in fisierul 1.txt este doar 1 linie scrisa, si vreau sa pun linia in clipboard.

ma poate ajuta cineva ? Multumesc.

P.S. Daca se poate rezolvare+explicare ar fi si mai bine pt mine.Nu sunt avansat.

Link to comment
Share on other sites


#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>

using namespace std;

int main () {
string line;
ifstream myfile ("1.txt");
getline (myfile,line);

HGLOBAL hText;
char *pText;
hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100);
pText = (char*)GlobalLock(hText);
char *linec;
linec = &line[0];
strcpy(pText, linec);
GlobalUnlock(hText);

OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_TEXT, hText);
CloseClipboard();
myfile.close();
return 0;
}

strcpy (char *, char *), si tu ai pus string. Am creat un pointer de tip char pe care l-am setat pe adresa primul caracter.

Edited by totti93
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...